How to create multipage pdf?

I wanted to create multipage pdf with fixed header and footer in every page. how to do that?
I tried doing in your invoice pdf example but only the product grid is moving to next page. i want to make constant header and footer to every page help me with this please.

1 Reply 1 reply marked as answer

AP Anand Panchamoorthi Syncfusion Team January 4, 2021 10:51 AM UTC

Hi Swastik Sharma, 

We can able to draw the header and footer in PDF document using PdfPageTemplateElement class. The header and footer contain the graphics support and automatic field support to perform their operations. 

Please find the sample code below to add header and footer to the PDF document 
//Create PDF document. 
final PdfDocument document = PdfDocument(); 
 
//Create a header template and draw image/text. 
final PdfPageTemplateElement headerElement = 
    PdfPageTemplateElement(const Rect.fromLTWH(0, 0, 515, 50)); 
headerElement.graphics.drawString( 
    'This is page header', PdfStandardFont(PdfFontFamily.helvetica, 10), 
    bounds: const Rect.fromLTWH(0, 0, 515, 50), 
    format: PdfStringFormat(lineAlignment: PdfVerticalAlignment.middle)); 
headerElement.graphics.setTransparency(0.6); 
headerElement.graphics.drawString( 
    'INVOICE', PdfStandardFont(PdfFontFamily.helvetica, 15), 
    bounds: const Rect.fromLTWH(0, 0, 515, 50), 
    format: PdfStringFormat( 
        alignment: PdfTextAlignment.right, 
        lineAlignment: PdfVerticalAlignment.middle)); 
headerElement.graphics 
    .drawLine(PdfPens.gray, const Offset(0, 49), const Offset(515, 49)); 
document.template.top = headerElement; 
 
//Create a footer template and draw a text. 
final PdfPageTemplateElement footerElement = 
    PdfPageTemplateElement(const Rect.fromLTWH(0, 0, 515, 50)); 
footerElement.graphics.drawString( 
  'This is page footer', 
  PdfStandardFont(PdfFontFamily.helvetica, 10), 
  bounds: const Rect.fromLTWH(0, 35, 515, 50), 
); 
footerElement.graphics.setTransparency(0.6); 
PdfCompositeField(text: 'Page {0} of {1}', fields: <PdfAutomaticField>[ 
  PdfPageNumberField(brush: PdfBrushes.black), 
  PdfPageCountField(brush: PdfBrushes.black)]).draw(footerElement.graphics, const Offset(450, 35)); 
document.template.bottom = footerElement; 

<---- Invoice code here ----> 

//Save PDF document. 
final List<int> bytes = document.save(); 

Please find the documentation from https://help.syncfusion.com/flutter/pdf/working-with-headers-and-footers and let us know if you need any further assistance in this. 

With Regards, 
Anand Panchamoorthi 


Marked as answer
Loader.
Up arrow icon