Reputation: 434
I'm trying to design a footer, but the footer needs to be absolute on every single page.
Is there a function to grab the bottom of the page? afterward I could just subtract a few pixels and add my footer there.
int bottom = document.GetBottom():
ct.SetSimpleColumn(20, 20, 0, bottom - 20);
something along that line? Thats just pseudo code though.
Upvotes: 1
Views: 455
Reputation: 434
the iTextSharp document provides document.Bottom which returns the bottom x value (atleast thats what worked for me)
using that I implemented a relative footer
PdfContentByte cb = wri.DirectContent;
ColumnText ct = new ColumnText(cb);
Phrase myText = new Phrase("footer data here", FontFactory.GetFont("Arial Bold", 10.0f, Font.BOLD, BaseColor.BLACK));
float textWidth = myText.Font.GetCalculatedBaseFont(false).GetWidthPoint("AASECT • 1444 I Street, NW • Suite 700 • Washington • DC • 20005 • (202) 449.1099 • [email protected]", 10.0f);
ct.SetSimpleColumn((doc.Right / 2) - (textWidth / 2), 1, (doc.Right / 2) + (textWidth / 2), doc.Bottom);
ct.AddText(myText);
ct.Go();
It creates the 'Phase' myText and then calculates the base font to gain access to the .GetWidthPoint to measure the size of the text. figures out the left most x coord by calculating the center of the document and subracting half of the width and repeats the reverse for the right most x coord by adding half of the width of the text
I hope this helps somebody, I found a lot of different 'Methods' of creating a footer and none of them worked, hopefully this meets someones needs.
Upvotes: 2