-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Optional page buffering #302
Conversation
This is the perfect solution to what I need to allow me to upgrade to the latest version and keeping the functionality of post page rendering operations. Thanks! |
This looks really nice, thank you! |
I like this solution, thanks for the PR. Just a few minor changes, and I think we can merge this. I think instead of creating |
@@ -19,6 +19,9 @@ class PDFDocument extends stream.Readable | |||
# Whether streams should be compressed | |||
@compress = @options.compress ? yes | |||
|
|||
if @options.bufferPages | |||
@_pageBuffer = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always create this array, regardless of @options.bufferPages
.
Sure, I like the proposed edits. I'll push an update. |
One more thing that might be confusing for some people is that Maybe we should keep a |
If we did change the meaning of But I think the dominant use case will be buffering all the pages until the end, and that case wouldn't benefit from this added complexity. So I prefer the API as it is. |
Yeah I agree about the dominant use case, but it still seems strange to me. Right now, if I call I think, if we keep it how it is, the method should be renamed to something like The complexity of the second solution is not that much, just one additional variable that would get incremented by |
Yeah, that sounds ok. Would you prefer
vs
|
The first one. I think just one method is better. |
Oops, I just realized I pushed the wrong version, hang on... |
Ok, all suggestions incorporated. |
Great, thanks so much for the PR! I know a lot of people have been itching for this feature for a few months, so glad to incorporate something for them. |
Sweet, glad to help. Thanks for fast merges. |
Awesome that this got merged so fast. Really looking forward to using this now! On Fri, Sep 12, 2014 at 8:06 PM, Devon Govett [email protected]
|
Just released v0.7.0 with this feature and lots of other fixes. Check it out! You can find docs on this particular feature, on the website. Thanks again, @ef4! |
😄 |
This closes #225 by adding an optional page buffer. The API works as follows:
bufferPages: true
when creating your document.doc.bufferedPageCount()
at any time to ask how many pages are buffered.doc.switchToPage(n)
to make any of the buffered pages the current page again. This lets you add additional content.doc.flushPages()
to flush the page buffer out to the underlying stream. This is optional, it also happens automatically atend()
.