flutterpdfflutter-layoutflutter-dependencies

How to break page when generating PDF from flutter PDF package


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 ?


Solution

  • 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
      }));