PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Dec 04, 2021 5:16 am

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed May 19, 2021 2:20 pm 

Joined: Wed May 19, 2021 1:57 pm
Posts: 1

How can I change my code to get a footer that says Page n of total. e.g. Page 1 of 3.

I can't seem to move my last paragraph to the bottom. Unless there is a better way.



private void Generate_PDF_Files(int number_of_pages, string output_folder, int sequence_number)
            string pdf_file_name = string.Format(@"{0}\PDFTest_{1}.pdf", output_folder, sequence_number.ToString("0000"));

            var enc1252 = Encoding.GetEncoding(1252);

            // Create a MigraDoc document
            Document document = new Document();

            // Add a section to the document
            Section section = document.AddSection();

            for (int page_number=1;page_number<=number_of_pages;page_number++)
                // Add a paragraph to the section
                MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
                string message = string.Format("Filename: {0}", System.IO.Path.GetFileName(pdf_file_name));

                paragraph.AddFormattedText(message, TextFormat.Bold);

                //MigraDoc.DocumentObjectModel.Shapes.Image img1 = section.AddImage(image_file_path);

                //img1.LockAspectRatio = true;
                //img1.Width = Unit.FromPoint(500);
                //img1.Height = Unit.FromPoint(300);

                //MigraDoc.DocumentObjectModel.Shapes.Image img2 = section.AddImage(image_file_path);

                //img2.LockAspectRatio = true;
                //img2.Width = Unit.FromPoint(500);
                //img2.Height = Unit.FromPoint(300);

                paragraph = section.AddParagraph();
                paragraph.Format.Alignment = ParagraphAlignment.Center;

                message = string.Format("Page {0} of {1}", page_number, number_of_pages);
                paragraph.AddFormattedText(message, TextFormat.Bold);

            const bool unicode = false;
            const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
            pdfRenderer.Document = document;


Reply with quote  
PostPosted: Wed May 19, 2021 7:21 pm 
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 683
Location: CCAA
Why not use the MigraDoc footer?

See "DefineContentSection" here:

For simple page numbers you do not need MigraDoc and can use PDFsharp to draw on existing PDF pages.

Best regards
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 38 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group