- How to add page numbers to your PDF
- Add text field to PDF
- Append multiple PDF documents
- Bulleted list from XML and XSL
- Merge PDF
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Convert TXT to PDF
- Convert XHTML to PDF
- Create PDF in C# - Tall Components - Check out our PDF code samples
- Text formatting
- Generate PDF form from XML
- Generate PDF with local images from XML with Xamarin.iOS
- XhtmlParagraph and TrueType fonts
- Add footer with left and right aligned text on same line
- Read and write meta data from PDF
- Stitch PDF documents
- Use multiple licenses
- What is the resulting fontsize in PDF rich text used in SimpleXhtmlShape
Add footer with left and right aligned text on same line
Add a footer to a PDF document that has left aligned text with a page number and right aligned text on the same line.
Document pdf = new Document();
Section section = pdf.Sections.Add();
// this bottom margin of the section determines the space available for the footer
section.Margin.Bottom = 100;
double width = section.PageSize.Width - section.Margin.Left - section.Margin.Right;
// filler text
for (int i=0; i<100; i++)
{
TextParagraph text = new TextParagraph();
text.SpacingAfter = 12;
section.Paragraphs.Add(text);
text.Fragments.Add(new Fragment("Generate PDF documents from scratch. Use code, XML/XSL or a combination."));
}
Footer footer = new Footer();
section.Footer = footer;
// the trick to have both left and right aligned
// text on the same line is to use a table
Table table = new Table();
// the footer will be top-aligned so to move it down you need
// to add spacing before the first paragraph of the footer
table.SpacingBefore = 12;
footer.Paragraphs.Add(table);
Row row = table.Rows.Add();
// left text
Cell leftCell = row.Cells.Add();
leftCell.PreferredWidth = width / 2;
TextParagraph leftText = new TextParagraph();
leftCell.Paragraphs.Add(leftText);
Fragment pageNumber = new Fragment("Page #p");
pageNumber.HasContextFields = true;
leftText.Fragments.Add(pageNumber);
// right text
Cell rightCell = row.Cells.Add();
rightCell.PreferredWidth = width / 2;
TextParagraph rightText = new TextParagraph();
rightText.HorizontalAlignment = HorizontalAlignment.Right;
rightCell.Paragraphs.Add(rightText);
Fragment title = new Fragment("TallPDF.NET");
rightText.Fragments.Add(title);
string path = "out.pdf";
using (FileStream file = new FileStream(path, FileMode.Create))
{
pdf.Write(file);
}
System.Diagnostics.Process.Start(path);