How to break page when generating PDF from flutter PDF package

930

you could just use two multipages like that:

pdf.addPage(pw.MultiPage(
  pageFormat: PdfPageFormat.a4,
  build: (pw.Context context) {
    return pw.Center(
      child:Column(
              children:[
                  pw.Text("Hello World"),
              ]
            )
    ); // Center
  }));
pdf.addPage(pw.MultiPage(
  pageFormat: PdfPageFormat.a4,
  build: (pw.Context context) {
    return pw.Center(
      child:Column(
              children:[
                  pw.Text("Hello 2"),
              ]
            )
    ); // Center
  }));
Share:
930
s.am.i
Author by

s.am.i

Updated on December 27, 2022

Comments

  • s.am.i
    s.am.i over 1 year

    I am trying to generate a pdf using flutter pdf package pdf ,Everything works fine but I want to generate sections on multiple pages below I added sample of my code

    final pdf = pw.Document();

    pdf.addPage(pw.MultiPage(
      pageFormat: PdfPageFormat.a4,
      build: (pw.Context context) {
        return pw.Center(
          child:Column(
                  children:[
                      pw.Text("Hello World"),
                      pw.Text("Hello 2"),
                  ]
                )
        ); // Center
      }));
    

    How to get Hello World on 1st page and Hello 2 on second page ?

  • s.am.i
    s.am.i about 3 years
    If i use like that when saving document is it coming as single pdf
  • Freddy Straub
    Freddy Straub about 3 years
    Sure one single pdf. Do you want multiple pdf files?
  • s.am.i
    s.am.i about 3 years
    No I need it as one.your answer was helpful