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.
SIGN IN To post a reply.
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 android studio sample from https://www.syncfusion.com/downloads/support/directtrac/general/ze/create_pdf_file1483248815
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
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
- Marked answer
-
SS Swastik Sharma
- Jan 1, 2021 09:23 AM UTC
- Jan 4, 2021 10:51 AM UTC