Home > Software engineering >  Add New Page in MultiPage Pdf Flutter
Add New Page in MultiPage Pdf Flutter

Time:10-06

I use the pdf library and MultiPage, and I want to repeat the specific widget so that each widget is on a separate page. How do I do that?

I don't want to use addPage because I have a header, footer and some formats don't want to repeat it in every add page.

How can I add a new page to a MultiPage that already has the same formats?

CodePudding user response:

// Create a PDF document.
final doc = pw.Document();

_logo = await rootBundle.loadString('assets/logo.svg');
_bgShape = await rootBundle.loadString('assets/invoice.svg');

=====> first_ Add page to the PDF <=======
doc.addPage(
  pw.MultiPage(
    pageTheme: _buildTheme(
      pageFormat,
      await PdfGoogleFonts.robotoRegular(),
      await PdfGoogleFonts.robotoBold(),
      await PdfGoogleFonts.robotoItalic(),
    ),
    header: _buildHeader,
    footer: _buildFooter,
    build: (context) => [
    //Insert to widget
    ],
  ),
);
======> second_ Add page to the PDF <========
doc.addPage(
  pw.MultiPage(
    pageTheme: _buildTheme(
      pageFormat,
      await PdfGoogleFonts.robotoRegular(),
      await PdfGoogleFonts.robotoBold(),
      await PdfGoogleFonts.robotoItalic(),
    ),
    header: _buildHeader,
    footer: _buildFooter,
    build: (context) => [
    //Insert to widget
    ],
  ),
);


// Return the PDF file content
return doc.save();
  • Related