Documentation
¶
Overview ¶
Package render turns a page of a PDF into pixels.
It reads with github.com/go-pdfkit/reader and rasterises with github.com/go-gfx/gfx. Nothing outside those and the standard library is used, so it builds for js/wasm and for every architecture the fleet targets — which is what lets a PDF be shown in a browser tab with nothing on the far end.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTimedOut = errors.New("render: the page was still being drawn when its time ran out")
ErrTimedOut says a page was still being drawn when its time ran out. The image returned with it holds what had been drawn by then.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Scale is device pixels per point. Zero means one, which is seventy-two
// to the inch; [Options.DPI] is the same thing said the other way.
Scale float64
// DPI sets the scale from dots per inch. It is ignored when Scale is set.
DPI float64
// Background is painted before anything else. The zero value is opaque
// white, which is what paper is.
Background *color.RGBA
// MaxPixels refuses a page that would come out larger than this, so a
// media box a file made up cannot be asked to fill memory. Zero means
// forty million, which is a little over A4 at 600 dots to the inch.
MaxPixels int
// NoAnnotations leaves out what the page carries beside its content: the
// notes, the highlights, the stamps, and the fields of a form. They are
// drawn by default, because a filled-in form drawn without them is a form
// with nothing in it.
NoAnnotations bool
// MaxDuration is how long the page may be drawn for. Zero means as long as
// it takes, which is what this did before there was anywhere to say
// otherwise.
//
// Some pages take a very long time. Of 59 432 corpus pages drawn at half
// as much again as their own size, 1 131 were still going after twenty
// seconds, and one figure took two hundred and seventy-three. A caller
// drawing somebody else's file — a browser tab, a queue of them, a server
// — cannot afford to wait for the worst of those and has, until now, had
// no way to say so: MaxPixels bounds what comes out, and nothing bounded
// the work of making it.
//
// When the time runs out the page stops being drawn and comes back as far
// as it got, with ErrTimedOut. That is deliberately not a blank: half a
// page is worth more than nothing to somebody scrolling, and the error
// says plainly that it is half.
MaxDuration time.Duration
// AllLayers draws every optional-content layer, including the ones the
// document's default configuration turns off.
//
// The default is to draw what the document says it shows when it is
// opened. On the corpus that is the same picture either way: 275 of the
// 1 633 real forms use optional content and 161 hide a group, but not one
// mark on any page of any of the 8 300 files measured falls inside a layer
// its own configuration hides. See optional.go for the numbers and for why
// the mechanism is read all the same.
//
// A caller that wants everything — a tool showing a layer panel, an
// archive comparing what a file holds against what it displays — sets
// this and gets the behaviour from before optional content was read.
AllLayers bool
}
Options say how a page is to be drawn.
Click to show internal directories.
Click to hide internal directories.