-
Notifications
You must be signed in to change notification settings - Fork 144
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
ResetPages() does not clear buffers #102
Comments
Hi, That is a very good point. ResetPages only takes care of the input in the current implementation, but it could clear the output as well. The comment does indicate that is how you should use it, so you are correct. |
I think I will just reset it every time it writes to the buffer on Create() or CreateContext() then it is always safe for reuse. Also, I am a bit surpised with this behaviour on Lambda. We use it with Docker Lambda's as well but our code creates a new generator using |
It is running on AWS lambda for me. I think the reason why it behaves like this, is that i am only initiating the PDF Generator once per lambda container. The handler function uses the following function to render the pdf
So it is not stored in global variables or anything - it just lives in the initiated containers memory. |
Hi, Thanks for explaining. In this case the PDF Generator object is indeed reused. Everything you declare in main is kept in memory as To make the behaviour of this package more predictable the buffer is now cleared before each run where the output will be written to the buffer. |
thanks for the fast reaction 👍 |
Hey
i'm using go-wkhtmltopdf in a lambda function to generate pdfs.
It works fine until the lambda container is re-used for another pdf generation.
To avoid issues i was calling
pdfg.ResetPages()
which looks on the first sight like the proper solution.After some time i found out that the generated file size increased and that some pdf readers start showing the data of the first execution and some printers print out multiple pages.
To fix this i'm now additionally calling
pdfg.Buffer().Reset()
together withpdfg.ResetPages()
Question now:
To me it looks a bit misleading that ResetPages() does not reset all page data - should the Buffer().Reset() be internally included in that ResetPages() function ?
The text was updated successfully, but these errors were encountered: