facebooktwittermenuarrow-up

GemBox Support Forum

Adding page with header/footer

I’d like to add a last page to a PDF document which has a header and footer. I’d like the new last page to be blank except for the header/footer.

Hi Linda,

Try this:

using (var document = PdfDocument.Load("input.pdf"))
{
    // Add new page.
    var page = document.Pages.Add();

    double marginLeft = 50;
    double marginRight = 50;
    double marginTop = 50;
    double marginBottom = 50;

    using (var formattedText = new PdfFormattedText())
    {
        // Write header.
        formattedText.Append("Sample Header");
        page.Content.DrawText(formattedText,
            new PdfPoint(marginLeft, page.CropBox.Top - marginTop - formattedText.Height));

        // Write footer.
        formattedText.Clear();
        formattedText.Append("Sample Footer");
        page.Content.DrawText(formattedText,
            new PdfPoint(page.CropBox.Width - marginRight - formattedText.Width, marginBottom));
    }

    document.Save("output.pdf");
}

Also, please check these examples as well:

I hope it helps.

Regards,
Mario