Documentation
¶
Overview ¶
Package pdfcanvas draws a go-webengine layout into a go-pdfkit page: a paint.Canvas whose paths, shadings, images and glyphs become the PDF's own, so the page keeps its text as text (subset-embedded fonts, with a /ToUnicode map, so it can be selected, searched and copied) and its edges as vectors.
doc := pdfkit.New(pdfkit.Options{Compress: true})
fonts := pdfcanvas.NewFonts()
l, _ := eng.LayoutHTML(ctx, html, base, image.Rect(0, 0, 1280, 720))
page := doc.AddPage(pdfkit.NewPageSize(960, 540))
l.PaintVector(pdfcanvas.New(page, 0.75, fonts))
A device pixel is mapped to scale points (0.75 for a CSS pixel at device scale 1: 1/96 in against 1/72 in) and the y axis is flipped, the page's top left being the layout's origin.
Index ¶
- func TextOf(n *dom.Node) string
- type Canvas
- func (c *Canvas) Clip(p *paint.Path, evenOdd bool)
- func (c *Canvas) Element(n *dom.Node) *pdfkit.StructElem
- func (c *Canvas) Fill(p *paint.Path, col css.Color, evenOdd bool)
- func (c *Canvas) Finish()
- func (c *Canvas) Glyphs(run *paint.GlyphRun)
- func (c *Canvas) Image(img image.Image, dst paint.Rect)
- func (c *Canvas) Mark(m paint.Mark)
- func (c *Canvas) Restore()
- func (c *Canvas) Save()
- func (c *Canvas) Shade(s paint.Shading)
- func (c *Canvas) Tag(parent *pdfkit.StructElem)
- type Fonts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Canvas ¶
type Canvas struct {
// Err is the first error a drawing call met (a font pdfkit cannot embed,
// a shading it refuses); the call that met it drew nothing, the others
// went on.
Err error
// contains filtered or unexported fields
}
Canvas is a paint.Canvas drawing into one pdfkit page.
func New ¶
New returns a canvas drawing into p, scale points per device pixel, with fonts shared across the document's pages. A nil fonts gets a map of its own.
func (*Canvas) Clip ¶
Clip implements paint.Canvas: the path, then W (or W*) and n, the clipping path operators of ISO 32000-1 §8.5.4.
func (*Canvas) Element ¶ added in v0.14.0
func (c *Canvas) Element(n *dom.Node) *pdfkit.StructElem
Element returns the structure element of a DOM node that has a role (an <a href>, a heading…), making it if no content of it was drawn yet: what a caller ties an annotation to (pdfkit.Page.AddTaggedLink). It returns nil for a node with no role of its own, or an artifact, or without Tag.
func (*Canvas) Finish ¶ added in v0.14.0
func (c *Canvas) Finish()
Finish closes the open sequence. Call it after PaintVector, before drawing anything else on the page.
func (*Canvas) Glyphs ¶
Glyphs implements paint.Canvas: the run's font, subset-embedded with a /ToUnicode map, and its glyphs at the layout's positions.
func (*Canvas) Image ¶
Image implements paint.Canvas. Pixel-identical images are embedded once per document (pdfkit content-addresses them).
func (*Canvas) Mark ¶ added in v0.14.0
Mark implements paint.StructuredCanvas: what is drawn next stands for m. The marked-content sequence opens at the next drawing.
func (*Canvas) Shade ¶
Shade implements paint.Canvas: an axial shading (type 2) for a linear gradient, a radial one (type 3) drawn under a transform that makes its circles the gradient's ellipses.
func (*Canvas) Tag ¶ added in v0.14.0
func (c *Canvas) Tag(parent *pdfkit.StructElem)
Tag makes the canvas write tagged content under parent, an element of the document's structure (typically pdfkit.Document.Structure(), or an element per page under it). Call it before PaintVector.