Search code examples
flutterdartpdfheader

Find the first page of a MultiPage in dart-pdf


I am creating PDF document using dart-pdf. It contains various sections that could be any number of pages in length. Each section starts on a new page. Currently I am adding a new MultiPage to the document for each section. How can I place a heading on only the first page of a given MultiPage

...
myPdf.addPage(
  MultiPage(
    header: (Context context) {
      //discover first page of this MultiPage here ???
      if(isFirstPage) {
        return Header()
      }
    }
  )
)

myPdf.addPage(
  MultiPage(
    header: (Context context) {
      //discover first page of this MultiPage here ???
      if(isFirstPage) {
        return Header()
      }
    }
  )
)
...

Solution

  • In all cases, you can do something like:

    var isFirstPage = true;
    
    myPdf.addPage(
      MultiPage(
        header: (Context context) {
          //discover first page of this MultiPage here ???
          if(isFirstPage) {
            isFirstPage = false;
            return Header()
          }
        }
      )
    )
    

    https://github.com/DavBfr/dart_pdf/issues/707#issuecomment-852458481