Go - converter.Convert() optimization opportunity?

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

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

is taking more than I thought it would

How much time did you expect?
What is the machine specs you are running on?

I can do to safely reuse an instance (or pool of instances) of Chromium to avoid the startup time associated with it?

No, though subsequent calls should be faster if only because the OS will have cached things for you.

For a three page document (with images)

Does your file reference external/remote resources (that require additional networking)?

Do you have particular throughput you need to achieve?