dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

This widget created more than 20 pages

Open merabtenei opened this issue 2 years ago • 6 comments

Describe the bug Using a large table or wrap with thousands of lines inside MultiPage caused an Exception (This widget created more than 20 pages)

To Reproduce Code snippet to reproduce the behavior:

pdf.addPage(
      MultiPage(build: (context) {
          return [
            Wrap(
                children: List.generate(
                    2000,
                    (idx) => SizedBox(
                        width: double.infinity,
                        child:
                            Text('DATA $idx', style: TextStyle(fontSize: 20)))))
          ];
        },

Is there a way to handle this ? I have a table with thousands of rows that can easily exceed 20 pages. What is the best way of doing this apart of splitting the Table into many small tables (Which may cause the header row to repeat in the middle of the page and may cause the rows to not be aligned as I use IntrinsicColumnWidth).

merabtenei avatar Sep 02 '22 11:09 merabtenei

Yes, this exception is raised only with debug code (asserts enabled). And you can raise the limit with the maxPages property of MultiPage

DavBfr avatar Sep 02 '22 11:09 DavBfr

Thanks for the quick answer, indeed I just saw the maxPages limit, increasing it worked. But now the PdfPreview took forever to display the 218 pages.

merabtenei avatar Sep 02 '22 11:09 merabtenei

Yes, this PdfPreview is not optimized for a big number of pages.

DavBfr avatar Sep 02 '22 11:09 DavBfr

Just checked the processing time : pdf.addPage( MultiPage( ... Took 44 seconds pdf.save() Took 29 seconds

I can understand why addPage is slow as I used IntrinsicColumnWidth calculation for the Table rows but I wonder why the save() method took this long too.

EDIT: Changing the IntrinsicColumnWidth to FlexColumnWidth reduced the time of pdf.save to 2.8 seconds. But MultiPage is still very slow.

merabtenei avatar Sep 02 '22 11:09 merabtenei

pdf.addPage( MultiPage computes the layout multiple times to make sure everything fits in the pages. pdf.save() might layout a last time to get the pages number correctly and render the final result to the file.

DavBfr avatar Sep 02 '22 12:09 DavBfr

Thanks for all the answers. I don't mind the time it takes as these are reports to generate once in many months, I'll just add a beautiful loading screen while it's processing and it won't matter a lot.

merabtenei avatar Sep 02 '22 12:09 merabtenei

pdf.addPage( MultiPage computes the layout multiple times to make sure everything fits in the pages. pdf.save() might layout a last time to get the pages number correctly and render the final result to the file.

Could processing time be optimized if fixed column widths are defined?

tulioccalazans avatar Feb 08 '23 13:02 tulioccalazans

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Apr 10 '23 00:04 github-actions[bot]

Closing this stale issue because it has no activity.

github-actions[bot] avatar Apr 15 '23 00:04 github-actions[bot]