Skip to content

Latest commit

 

History

History

http-server-advanced

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Overview

The example showcases a configurable web page to PDF conversion server.

The problem

The biggest challenge is that wkhtmltopdf can only run on the main thread, the problem being that the HTTP server runs each request in a separate goroutine.

For more information, see:
wkhtmltopdf/wkhtmltopdf#1711
https://forum.dlang.org/thread/[email protected]
https://forum.qt.io/topic/84485/qapplication-not-created-in-main-thread/9

The solution

The solution is to run the conversion process on the main thread. This can be achieved as shown here. There are also a couple of packages which facilitate this, like faiface/mainthread or olahol/mainthread. The example does not use any external library to access the main thread.

Usage

Run the conversion server.

go run main.go

Make a conversion request.

curl -H "Content-Type: application/json" -X POST \
    -o google.pdf 127.0.0.1:8080 \
    -d'{
	"converterOpts": {
		"title": "google.com",
		"paperSize": "A4",
		"orientation": "Portrait"
	},
	"objectOpts": {
		"location": "https://google.com",
		"footer": {
			"contentCenter": "[page]"
		}
	}
}'

See full list of options at https://pkg.go.dev/github.com/adrg/go-wkhtmltopdf.