Comments (5)
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 will update it later today, add a few tests and publish a new version.
from go-wkhtmltopdf.
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 wkhtmltopdf.NewPDFGenerator()
for every PDF anyway so the buffer is not reused. Performance wise this is OK, the lookup of wkhtmltopdf on the system is the heaviest part and that is cached by the package internally in a global variable. So you could just create a new instance each time as a workaround.
Are using global variables to store the state between executions?
from go-wkhtmltopdf.
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 main() function contains this line (and some additional configs...)
pdfg, err := wkhtmltopdf.NewPDFGenerator()
It is only called once per container initialization and keeps that object in memory.
The handler function uses the following function to render the pdf
func (h handler) renderPdf() ([]byte) {
h.pdfgen.ResetPages()
h.pdfgen.Buffer().Reset() // added
h.pdfgen.AddPage(page)
h.pdfgen.Create()
return h.pdfgen.Bytes()
}
So it is not stored in global variables or anything - it just lives in the initiated containers memory.
from go-wkhtmltopdf.
Hi,
Thanks for explaining. In this case the PDF Generator object is indeed reused. Everything you declare in main is kept in memory as Lambda.Start()
never returns, it just calls your handler (renderPdf()) for each invocation. Similar to http.ListenAndServe
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.
https://github.com/SebastiaanKlippert/go-wkhtmltopdf/releases/tag/v1.8.0
from go-wkhtmltopdf.
thanks for the fast reaction π
from go-wkhtmltopdf.
Related Issues (20)
- Identify Blank PDF generated by go-wkhtmltopdf HOT 1
- Warning: Blocked access to file C:/Users/Administrator/.... HOT 2
- undefined: exec.ErrDot HOT 2
- Can't create Docker build HOT 1
- Margin setting support mm HOT 2
- "built against an unpatched version of QT" with active TOC HOT 3
- emoji not support HOT 1
- Go get not working for v1.9.0 Feb 11, 2023 HOT 13
- GetPath function return nothing.
- SetPath permission denied HOT 1
- CSS Display flex don't work. HOT 1
- do not support convert SPA to pdf
- How to set footer styles HOT 1
- Error failed to load... network status 301 HOT 8
- Second page of pdf don't display any content HOT 1
- PDF has blank pages from second page onwards HOT 4
- Create() returning not nil error on valid html HOT 12
- η¨δΊθ―₯εΊεοΌιθ¦ε¨εͺιζΎθ΅ζΊοΌδΌεε εεοΌ HOT 1
- wkhtmltopdf not found HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-wkhtmltopdf.