Add footer to PDF

Shapes
8/13/2014

Downloads

This code sample shows how to add a footer in a PDF document.

C# code sample

1 using (FileStream fileIn = new FileStream(@"..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)) 2 { 3 Document pdf = new Document(fileIn); 4 foreach (Page page in pdf.Pages) 5 { 6 TextShape text = new TextShape("your footer text here", Font.Helvetica, 14); 7 8 // calculate position of text 9 TranslateTransform translate = new TranslateTransform(); 10 translate.X = (page.Width - text.MeasuredWidth) / 2; // center 11 translate.Y = text.MeasuredHeight + 20; // some bottom margin 12 13 // apply the transform to the text 14 text.Transform = translate; 15 16 // add text to page 17 page.Overlay.Add(text); 18 } 19 20 using (FileStream fileOut = new FileStream(@"..\..\stamped.pdf", FileMode.Create, FileAccess.Write)) 21 { 22 pdf.Write(fileOut); 23 } 24 }

VB.NET code sample

1 Using fileIn As New FileStream("..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read) 2 Dim pdf As New Document(fileIn) 3 For Each page As Page In pdf.Pages 4 Dim text As New TextShape("your footer text here", Font.Helvetica, 14) 5 6 ' calculate position of text 7 Dim translate As New TranslateTransform() 8 translate.X = (page.Width - text.MeasuredWidth) / 2 9 ' center 10 translate.Y = text.MeasuredHeight + 20 11 ' some bottom margin 12 ' apply the transform to the text 13 text.Transform = translate 14 15 ' add text to page 16 page.Overlay.Add(text) 17 Next 18 19 Using fileOut As New FileStream("..\..\stamped.pdf", FileMode.Create, FileAccess.Write) 20 pdf.Write(fileOut) 21 End Using 22 End Using

The original page:

PDF-to-add-footer-to.png

The PDF page with the footer:

pdf-with-footer.png