Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 864509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:29:25+00:00 2026-05-15T09:29:25+00:00

I am almost done with implementing a printing functionality, but I am having trouble

  • 0

I am almost done with implementing a printing functionality, but I am having trouble getting the last hurdle done with.

My problem is, that I am printing some reports, consisting of a header (with information about the person the report is about), a footer (with a page number) and the content in the middle, which is a FlowDocument. Since the flowdocuments can be fairly long, It is very possible that they will span multiple pages.

My approach is to make a custom FlowDocumentPaginator which derives from DocumentPaginator.

In there i define my header and my footer.

However, when I print my page, the flowdocument and my header and footer are on top of eachother.

So my question is plain and simple – how do I define from where and to where the flowdocument part on the pages will be placed?

here is the code from my custommade Paginator:

public class HeaderedFlowDocumentPaginator : DocumentPaginator
{
    private DocumentPaginator flowDocumentpaginator;

    public HeaderedFlowDocumentPaginator(FlowDocument document)
    {
        flowDocumentpaginator = ((IDocumentPaginatorSource) document).DocumentPaginator;
    }

    public override bool IsPageCountValid
    {
        get { return flowDocumentpaginator.IsPageCountValid; }
    }

    public override int PageCount
    {
        get { return flowDocumentpaginator.PageCount; }
    }

    public override Size PageSize
    {
        get { return flowDocumentpaginator.PageSize;  }
        set { flowDocumentpaginator.PageSize = value; }
    }

    public override IDocumentPaginatorSource Source
    {
        get { return flowDocumentpaginator.Source; }
    }

    public override DocumentPage GetPage(int pageNumber)
    {
        DocumentPage page = flowDocumentpaginator.GetPage(pageNumber);

        ContainerVisual newVisual = new ContainerVisual();
        newVisual.Children.Add(page.Visual);

        DrawingVisual header = new DrawingVisual();
        using (DrawingContext dc = header.RenderOpen())
        {
            //Header data
        }
        newVisual.Children.Add(header);

        DrawingVisual footer = new DrawingVisual();
        using (DrawingContext dc = footer.RenderOpen())
        {
            Typeface typeface = new Typeface("Trebuchet MS");
            FormattedText text = new FormattedText("Page " + (pageNumber + 1).ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 14, Brushes.Black);

            dc.DrawText(text, new Point(page.Size.Width - 100, page.Size.Height-30));
        }

        newVisual.Children.Add(footer);

        DocumentPage newPage = new DocumentPage(newVisual);
        return newPage;
    }
}

And here is the printdialogue call:

private void btnPrint_Click(object sender, RoutedEventArgs e)
{
    try
    {
        PrintDialog printDialog = new PrintDialog();
        if (printDialog.ShowDialog() == true)
        {
            FlowDocument fd = new FlowDocument();
            MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(<My string of text - RTF formatted>));

            TextRange tr = new TextRange(fd.ContentStart, fd.ContentEnd);
            tr.Load(stream, DataFormats.Rtf);

            stream.Close();
            fd.ColumnWidth = printDialog.PrintableAreaWidth;

            HeaderedFlowDocumentPaginator paginator = new HeaderedFlowDocumentPaginator(fd);

            printDialog.PrintDocument(paginator, "myReport");
        }
    }
    catch (Exception ex)
    {
        //Handle
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:29:25+00:00Added an answer on May 15, 2026 at 9:29 am

    I found it myself – there is a function called pagepadding, where I can set the distance from the four sides of the paper 🙂

    Fairly easy solution – I just didn’t know what to look for

    Example:

    Flowdocument fd = new FlowDocument();
    
    fd.PagePadding = new Thickness(0.25,160,0.25,45);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 447k
  • Answers 447k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Python doesn't have the same compilation process as C so… May 15, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer One easy option: list.OrderBy(r => r.Milestone ?? DateTime.MaxValue) That won't… May 15, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer Documentation Example android:maxLength="10" May 15, 2026 at 7:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.