Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds some ways the dart_pdf to avoid excessive memory consumption when producing many page PDFs with lots of source data.
ability to call postProcess on pw.Page as soon as the page has been added to the document. In my case, the pw.Page's build-method holds a reference to the data provided earlier by an async function (so cannot be called from build), and that used up to 1GB of RAM on a large PDF. Calling postProcess after adding the page, allows freeing the data resulting the memory consumption drop >500MB => 5MB
ability to save the PDF directly to the file stream. This is done by changin PdfStream into an abstract base class with two implementations: PdfStreamBuffer and PdfStreamFile. Most of the internal use of old PdfStream is now using PdfStreamBuffer. A new top level method saveFile was added that takes a File object as an argument to save the data. This saves a lot of memory when doing the final writing of the PDF.
Feel free to editorialize this PR as you see fit.