Hello,
I’m putting together some proof-of-concepts around PDF generation to get a feel for the PDFTron SDK. Right now I’m working on a Go project and I want to be able to convert HTML to PDF.
I have a working sample that is getting the job done, but the call to converter.Convert(doc)
is taking more than I thought it would. For a three page document (with images) to convert from HTML to PDF took 935ms total. 823ms of that time is spent on the call to converter.Convert(doc)
.
The proportions of the timing makes sense to me, but I was wondering if there were any known tricks that I can do to safely reuse an instance (or pool of instances) of Chromium to avoid the startup time associated with it?
Below is my POC function:
func CreatePDF(html string) ([]byte, error) {
doc := pdftron.NewPDFDoc()
converter := pdftron.NewHTML2PDF()
m := "0.4 in"
converter.SetMargins(m, m, m, m)
converter.InsertFromHtmlString(html)
if !converter.Convert(doc) {
logEntry := converter.GetLog()
err := fmt.Errorf("PDF conversion failed: %s\n", logEntry)
return []byte{}, err
}
// Convert to []byte
content := (doc.Save(uint(pdftron.SDFDocE_linearized))).(pdftron.VectorUnChar)
buffer := make([]byte, int(content.Size()))
for i := 0; i < int(content.Size()); i++ {
buffer[i] = content.Get(i)
}
return buffer, nil
}
Thanks,
Ben