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 ¶
- type Canvas
- func (c *Canvas) Clip(p *paint.Path, evenOdd bool)
- func (c *Canvas) Fill(p *paint.Path, col css.Color, evenOdd bool)
- func (c *Canvas) Glyphs(run *paint.GlyphRun)
- func (c *Canvas) Image(img image.Image, dst paint.Rect)
- func (c *Canvas) Restore()
- func (c *Canvas) Save()
- func (c *Canvas) Shade(s paint.Shading)
- type Fonts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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) Glyphs ¶
Glyphs implements paint.Canvas: the run's font, subset-embedded with a /ToUnicode map, and its glyphs at the layout's positions.