Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: output to file stream #1816

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

petri-lipponen-movesense

This PR adds some ways the dart_pdf to avoid excessive memory consumption when producing many page PDFs with lots of source data.

  1. 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

  2. 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.

- implement saveFile -methods in document
- make PdfStream as abstract base with buffer and file implementations
- change all temp uses of PdfStream to use PdfStreamBuffer
@petri-lipponen-movesense
Copy link
Author

Looks like there is something I don't understand about the unit tests, since they don't pass. I couldn't run them on my mac (couldn't find font files for some reason), so I'm needing some help fixing them.

@DavBfr
Copy link
Owner

DavBfr commented Jan 30, 2025

Looks like there is something I don't understand about the unit tests, since they don't pass. I couldn't run them on my mac (couldn't find font files for some reason), so I'm needing some help fixing them.

No issues. I'll check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants