Documentation
¶
Index ¶
- Variables
- type Dest
- type DestKind
- type Options
- type PDF
- func (r *PDF) AddAnchor(name string, rect canvas.Rect)
- func (r *PDF) AddAnchorToPage(page int, name string, rect canvas.Rect)
- func (r *PDF) AddDestToPage(page int, pageHeight float64, name string, dest Dest)
- func (r *PDF) AddLink(uri string, rect canvas.Rect)
- func (r *PDF) AddOutline(name string, level int, y float64)
- func (r *PDF) AddOutlineToPage(page int, pageHeight float64, name string, level int, dest Dest)
- func (r *PDF) Close() error
- func (r *PDF) NewPage(width, height float64)
- func (r *PDF) RenderCanvas(scene *canvas.Canvas, m canvas.Matrix)
- func (r *PDF) RenderCanvasWith(scene *canvas.Canvas, m canvas.Matrix, draw func())
- func (r *PDF) RenderImage(img image.Image, m canvas.Matrix)
- func (r *PDF) RenderPath(path *canvas.Path, style canvas.Style, m canvas.Matrix)
- func (r *PDF) RenderText(text *canvas.Text, m canvas.Matrix)
- func (r *PDF) SetImageEncoding(enc cimage.ImageEncoding)
- func (r *PDF) SetInfo(title, subject, keywords, author, creator string)
- func (r *PDF) SetLang(lang string)
- func (r *PDF) Size() (float64, float64)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Dest ¶
Dest describes a named destination. Coordinates are in millimetres with the origin at the top left of the target page, matching the source formats this is fed from; they are converted to PDF's bottom-left origin when written.
Which fields matter depends on Kind: Fit uses none, FitH uses Y, FitV uses X, XYZ uses X, Y and Zoom, and FitR uses X0, Y0, X1 and Y1.
type DestKind ¶
type DestKind int
DestKind is a named destination type, matching the PDF destination styles.
const ( // DestFit fits the whole page in the window. DestFit DestKind = iota // DestFitH fits the page height and scrolls to Y. DestFitH // DestFitV fits the page width and scrolls to X. DestFitV // DestXYZ scrolls to X, Y and applies Zoom. A Zoom of 0 keeps the current one. DestXYZ // DestFitR fits the X0, Y0 to X1, Y1 rectangle in the window. DestFitR )
type PDF ¶
type PDF struct {
// contains filtered or unexported fields
}
PDF is a portable document format renderer.
func (*PDF) AddAnchor ¶
AddAnchor adds an anchor that can be referenced by a link (see AddLink). The rectangle is the area to be referenced. If the width and height are zero and the X and Y positions are zero, it will fit the entire page. If either width/height and X/Y are zero then it will fit the page's height/width and scroll to the X/Y position. Otherwise, if the width and height are zero and X and Y are not zero, it will scroll to the position but not change it's zoom.
func (*PDF) AddAnchorToPage ¶
AddAnchorToPage adds an anchor bound to the given page index instead of the current page. The destination name tree is only built in Close, and the page references it indexes are known by then, so an anchor may be registered before its target page is created. Links that point backwards — a link on a later page targeting an earlier one — cannot use AddAnchor, which would bind them to whichever page happens to be current.
func (*PDF) AddDestToPage ¶
AddDestToPage registers a named destination of an explicit kind on the given page, which a link can then point at with AddLink("#" + name).
It is the unambiguous counterpart to AddAnchor, which infers the destination type from the shape of a rectangle and therefore cannot express, for example, an XYZ destination at x = 0 — indistinguishable from a FitH — or a non-zero zoom, which the inferred form always writes as zero. Prefer this whenever the destination type is known.
pageHeight is the height of the target page in millimetres: Dest coordinates use the top left as their origin while PDF uses the bottom left, so the conversion needs the page height. It may differ from the current page's height, and passing the wrong value flips the destination vertically.
func (*PDF) AddLink ¶
AddLink adds a link at the given rectangle. If the URI starts with # this will link to an anchor (set with AddAnchor).
func (*PDF) AddOutline ¶
AddOutline adds an outline element at the given y position. The top-level element must have level zero. If any level is missing, then higher level elements are ignored.
func (*PDF) AddOutlineToPage ¶
AddOutlineToPage adds an outline entry of an explicit destination kind, bound to the given page rather than to the current one.
It is the counterpart to AddAnchorToPage and AddDestToPage. AddOutline infers the destination from y alone, which can only express Fit and FitH; pass dest to state the kind directly. The outline tree is written in Close, so an entry may be registered before its target page exists; entries whose target page never gets written are dropped along with their descendants.
level is the nesting depth, zero for a top-level entry, and entries are expected in document order — the tree is rebuilt from the levels, the way AddOutline does.
pageHeight is the height of the target page in millimetres; see Dest.
func (*PDF) RenderCanvas ¶
RenderCanvas embeds an immutable canvas as a Form XObject, reused by identity within this PDF. Other PDFs get independent objects and resource references.
func (*PDF) RenderCanvasWith ¶
RenderCanvasWith is RenderCanvas with an optional renderer adapter. draw is called synchronously, only when the Form is first built, with r temporarily targeting the Form. The callback must render the scene in local coordinates and must not add pages, links, anchors or outlines. The same scene identity must always use equivalent rendering settings.
func (*PDF) RenderImage ¶
RenderImage renders an image to the canvas using a transformation matrix.
func (*PDF) RenderPath ¶
RenderPath renders a path to the canvas using a style and a transformation matrix.
func (*PDF) RenderText ¶
RenderText renders a text object to the canvas using a transformation matrix.
func (*PDF) SetImageEncoding ¶
func (r *PDF) SetImageEncoding(enc cimage.ImageEncoding)
SetImageEncoding sets the image encoding to Loss or Lossless.