EVO HTML to PDF Converter

Add HTML in Header and Footer

EVO PDF Client for .NET Documentation

EVO HTML to PDF Converter offers a great flexibility in adding headers and footers to the generated PDF document. You can add in header and footer any PDF element that you can normally add in a PDF page : HTML, text, image.

The most important options related to adding HTML in header and footer:

Enable Header and Footer

Header Options

Footer Options

Code Sample - Add HTML in Header and Footer

C#
protected void createPdf()
{
    // Get the server IP and port
    String serverIP = textBoxServerIP.Text;
    uint serverPort = uint.Parse(textBoxServerPort.Text);

    // Create a PDF document
    Document pdfDocument = null;
    if (radioButtonUseTcpService.Checked)
        pdfDocument = new Document(serverIP, serverPort);
    else
        pdfDocument = new Document(true, textBoxWebServiceUrl.Text);

    // Set optional service password
    if (textBoxServicePassword.Text.Length > 0)
        pdfDocument.ServicePassword = textBoxServicePassword.Text;

    // Set license key received after purchase to use the converter in licensed mode
    // Leave it not set to use the converter in demo mode
    pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

    // Add a PDF page to PDF document
    PdfPage pdfPage = pdfDocument.AddPage();

    HtmlToPdfElement htmlToPdfElement = null;

    // Add document header
    if (addHeaderCheckBox.Checked)
        AddHeader(pdfDocument, drawHeaderLineCheckBox.Checked);

    // Add document footer
    if (addFooterCheckBox.Checked)
        AddFooter(pdfDocument, addPageNumbersInFooterCheckBox.Checked, drawFooterLineCheckBox.Checked);

    // Create a HTML to PDF element to add to document
    htmlToPdfElement = new HtmlToPdfElement(0, 0, urlTextBox.Text);

    // Optionally set a delay before conversion to allow asynchonous scripts to finish
    htmlToPdfElement.ConversionDelay = 2;

    // Optionally add a space between header and the page body
    // Leave this option not set for no spacing
    htmlToPdfElement.Y = float.Parse(firstPageSpacingTextBox.Text);
    htmlToPdfElement.TopSpacing = float.Parse(headerSpacingTextBox.Text);

    // Optionally add a space between footer and the page body
    // Leave this option not set for no spacing
    htmlToPdfElement.BottomSpacing = float.Parse(footerSpacingTextBox.Text);

    // Set header visibility
    pdfDocument.GetPage(0).ShowHeader = showHeaderInFirstPageCheckBox.Checked;
    htmlToPdfElement.ShowHeaderInEvenPages = showHeaderInEvenPagesCheckBox.Checked;
    htmlToPdfElement.ShowHeaderInOddPages = showHeaderInOddPagesCheckBox.Checked;

    // Set footer visibility
    pdfDocument.GetPage(0).ShowFooter = showFooterInFirstPageCheckBox.Checked;
    htmlToPdfElement.ShowFooterInEvenPages = showFooterInEvenPagesCheckBox.Checked;
    htmlToPdfElement.ShowFooterInOddPages = showFooterInOddPagesCheckBox.Checked;

    // Add the HTML to PDF element to document
    // This will raise the PrepareRenderPdfPageEvent event where the header and footer visibilit per page can be changed
    pdfPage.AddElement(htmlToPdfElement);

    // Save the PDF document in a memory buffer
    byte[] outPdfBuffer = pdfDocument.Save();
}