Documentation ¶
Overview ¶
lazypress converts HTML pages to PDF looking just like they would render in the browser. Under-the-hood, it is using Google Chrome (via github.com/chromedp/chromedp) to load the HTML so the PDF looks just like if you would print it from the browser. It also comes with a built-in HTML sanitizer (uses github.com/microcosm-cc/bluemonday). You can use this code as a library, or you can run it as a server which will spit out PDFs when you send HTML to it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitServer ¶
InitServer initializes the server. It takes the port to listen on and the path to the chrome executable. If the chrome executable is not provided, the server will use the default options of github.com/chromedp/chromedp. The default port is 3444.
func SanitizeHTML ¶
SanitizeHTML sanitizes the HTML using github.com/microcosm-cc/bluemonday.
Types ¶
type PDF ¶
type PDF struct { Content []byte Settings page.PrintToPDFParams Exporter io.Writer Closer io.Closer Sanitize bool // contains filtered or unexported fields }
PDF represents a PDF document as it is used by lazypress.
func (PDF) Export ¶
Export outputs the generated PDF to the configured output. See LoadSettings to configure the output type.
func (*PDF) GenerateWithChrome ¶
GenerateWithChrome creates a PDF from the given HTML using Google Chrome. It accepts a context.Context to allow for cancellation and customization of the Chrome process. It accepts a []byte of HTML to be loaded into the browser. It returns a pointer to a PDF struct.
func (*PDF) LoadSettings ¶
LoadSettings loads a map[string]string of settings to configure the PDF. The map can contain the following keys: - output: the output type. Can be "file", "download". - filename: the filename to use when outputting to a file. - sanitize: whether to sanitize the HTML. Since we are also using the same settings as the github.com/chromedp/cdproto/page, you can also use the same keys. See https://pkg.go.dev/github.com/chromedp/cdproto/page#PrintToPDFParams for more information.