Search code examples
footerhtml-to-pdfpage-numberingevopdf

Create footer with page number not displayed using Document object of EvoPdf


I have a pdf file that converted from html by EvoPdf HtmlToPdfConverter. I read the file bytes by evopdf Document Class and add footer element to it. after saving the bytes - it's displaying inline webBrowser. the footer with page number isn't displayed.

This is my code:

Document pdfDoc = new Document("myFilePath.pdf");

//create the footer element
TextElement footerText = new TextElement(0, 30, "Page &p; of &P;  ",
        new System.Drawing.Font( new System.Drawing.FontFamily("Arial"), 10, System.Drawing.GraphicsUnit.Point));
footerText.EmbedSysFont = true;
footerText.TextAlign = HorizontalTextAlign.Right;
pdfDoc.AddFooterTemplate(50);
pdfDoc.Footer.AddElement(footerText);

byte[] outBuffer = pdfDoc.Save();
pdfDoc.Close();
//...

If I add the footer element to the htmlToPdfConverter it displayed well.

how can I display it?

Thanks.


Solution

  • I have also run into the same situation. Basically, I wanted to add header and footer to existing PDFs without using htmltopdfconverter.

    Here is the solution with a few tweaks to your existing code:

    //Create a blank document.
    Document MergeDocument = new Document(); 
    Document pdfDoc = new Document("myFilePath.pdf");
    
    //Merged n number of existing PDFs to newly created document.
    MergedDocument.AppendDocument(pdfDoc, true, true, true);
    
    //create the footer element
    TextElement footerText = new TextElement(0, 30, "Page &p; of &P;  ",
        new System.Drawing.Font( new System.Drawing.FontFamily("Arial"), 10, System.Drawing.GraphicsUnit.Point));
    footerText.EmbedSysFont = true;
    footerText.TextAlign = HorizontalTextAlign.Right;
    
    //Apply footer to the newly created document after all documents appended.
    MergeDocument.AddFooterTemplate(50);
    MergeDocument.Footer.AddElement(footerText);
    
    byte[] outBuffer = MergeDocument.Save();
    
    MergeDocument.Close();