goweasyprint

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

README

go-weasyprint

Golang port of Weasyprint python Html to Pdf library.

This is an ongoing work, not production ready just yet.

Outline

This package converts an HTML document (with its associated CSS files) to a PDF file. The heavy lifting is actually delegated to webrender, but this package implements a backend for PDF files, relying on benoitkugler/pdf.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HtmlToPdf

func HtmlToPdf(target io.Writer, htmlContent utils.ContentInput, fontConfig text.FontConfiguration) error

HtmlToPdf performs the convertion of an HTML document (`htmlContent`) to a PDF file, written in `target`. It is a wrapper around the following steps :

  • `tree.NewHTML` parses the input files (HTML and CSS)
  • `document.Render` layout the document, creating an intermediate representation ...
  • ... which is transformed into an in-memory PDF by `document.WriteDocument`, using the `pdf.Ouput` backend.
  • model.Write eventually serialize the PDF into `target`

See `HtmlToPdfOptions` for more options.

func HtmlToPdfOptions

func HtmlToPdfOptions(target io.Writer, htmlContent utils.ContentInput, baseUrl string, urlFetcher utils.UrlFetcher,
	mediaType string, stylesheets []tree.CSS, presentationalHints bool, fontConfig text.FontConfiguration, zoom float64, attachments []backend.Attachment,
) error

HtmlToPdfOptions is the same as HtmlToPdf, with control overs the following parameters:

  • `baseUrl` is used as reference for links (stylesheets, images, etc...). If empty, it is deduced from the html content.
  • `urlFetcher` is a function called when resolving resources. If nil, it defaults to `utils.DefautUrlFetcher`.
  • `mediaType` is the CSS media type used to query CSS rules. It defaults to "print".
  • `presentationHints` controls whether or not the additional presentation stylesheet is used.
  • `zoom` is a zoom factor
  • `attachements` is an additional list of attachements to include into the PDF file.

Types

This section is empty.

Directories

Path Synopsis
Package pdf implements the backend needed to draw a document, using github.com/benoitkugler/pdf.
Package pdf implements the backend needed to draw a document, using github.com/benoitkugler/pdf.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL