I tried but I get the footer cutted off.
public class PdfBuilder
{
private PdfDocument _document;
private float _pageWidth => _document.Pages[0].GetClientSize().Width;
private float _pageHeight => _document.Pages[0].GetClientSize().Height;
public PdfBuilder()
{
_document = new PdfDocument();
}
public void SetMargin(float top, float left, float bottom, float right)
{
_document.PageSettings.Margins.Top = top;
_document.PageSettings.Margins.Left = left;
_document.PageSettings.Margins.Right = bottom;
_document.PageSettings.Margins.Bottom = right;
}
public void AddPageToDocument()
{
//Add a page to the document
_document.Pages.Add();
}
public void AddFooter()
{
RectangleF rect = new RectangleF(0, 0, _pageWidth, 50);
//Create a Page template that can be used as footer.
PdfPageTemplateElement footer = new PdfPageTemplateElement(rect);
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
PdfBrush brush = new PdfSolidBrush(Color.Black);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);
//Create page count field.
PdfPageCountField count = new PdfPageCountField(font, brush);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Copyright " + DateTime.Now.Year + " This the company name " + DateTime.Now.ToLongDateString() + "this the website - Pag. {0} / {1}", pageNumber, count);
compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
compositeField.Bounds = footer.Bounds;
//Draw the composite field in footer.
compositeField.Draw(footer.Graphics, new PointF(0, 45));
//Add the footer template at the bottom.
_document.Template.Bottom = footer;
}
}