pdf

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package pdf renders PDF documents.

doc, err := pdf.Open("file.pdf")
defer doc.Close()

p, err := doc.Page(0)
img, err := p.ImageDPI(150)
txt, err := p.Text()

A page also reads as structured text, as its links, as SVG and as HTML, and Page.Run draws it through a Device. The device interface and the devices behind it live in the gfx package and are aliased here, so that rendering a page needs one import.

A page composites in one color space throughout and converts once, at the public boundary, so a CMYK document renders to *image.CMYK.

A damaged file renders the part that could be read. What went wrong is collected in Document.Err rather than returned, unless Options.Strict asks for the first of them to be.

A Document may be rendered from several goroutines at once, one page each; a Page may not. Configuration belongs before they start.

Index

Constants

View Source
const (
	KindGray       = gfx.KindGray
	KindRGB        = gfx.KindRGB
	KindCMYK       = gfx.KindCMYK
	KindLab        = gfx.KindLab
	KindCalRGB     = gfx.KindCalRGB
	KindCalGray    = gfx.KindCalGray
	KindIndexed    = gfx.KindIndexed
	KindSeparation = gfx.KindSeparation
	KindDeviceN    = gfx.KindDeviceN
	KindPattern    = gfx.KindPattern
)

Color space families, ISO 32000-1 8.6.

View Source
const (
	BlendNormal     = gfx.BlendNormal
	BlendMultiply   = gfx.BlendMultiply
	BlendScreen     = gfx.BlendScreen
	BlendOverlay    = gfx.BlendOverlay
	BlendDarken     = gfx.BlendDarken
	BlendLighten    = gfx.BlendLighten
	BlendColorDodge = gfx.BlendColorDodge
	BlendColorBurn  = gfx.BlendColorBurn
	BlendHardLight  = gfx.BlendHardLight
	BlendSoftLight  = gfx.BlendSoftLight
	BlendDifference = gfx.BlendDifference
	BlendExclusion  = gfx.BlendExclusion
	BlendHue        = gfx.BlendHue
	BlendSaturation = gfx.BlendSaturation
	BlendColor      = gfx.BlendColor
	BlendLuminosity = gfx.BlendLuminosity
)

The separable blend modes, then the four non-separable ones.

View Source
const DefaultContentCacheOps = 1 << 18

DefaultContentCacheOps is how many operands of parsed content streams a document keeps when nothing says otherwise.

View Source
const DefaultImageCacheBytes = 1 << 26

DefaultImageCacheBytes is how much of a document's decoded images are kept when nothing says otherwise.

View Source
const DefaultPixelLimit = 1 << 28

DefaultPixelLimit is how many pixels a page may allocate when Options says nothing, the same number and the same name as in the sibling codecs.

Variables

View Source
var (
	DeviceGray = gfx.DeviceGray
	DeviceRGB  = gfx.DeviceRGB
	DeviceCMYK = gfx.DeviceCMYK
)

The device spaces, which every content stream can use without declaring.

View Source
var (
	// ErrInvalid means the file is not a PDF, or is damaged past recovery.
	ErrInvalid = syntax.ErrInvalid
	// ErrUnsupported means the file is well formed but uses something this
	// package cannot handle.
	ErrUnsupported = syntax.ErrUnsupported
	// ErrPassword means the document is encrypted and the password is wrong.
	ErrPassword = syntax.ErrPassword
)

Errors returned by this package. Anything a damaged file does that can be worked around is recorded in Document.Err instead.

View Source
var DefaultColorParams = gfx.DefaultColorParams

DefaultColorParams is what a page starts with.

Functions

func RegisterImageDecoder

func RegisterImageDecoder(filter Name, dec ImageDecoder)

RegisterImageDecoder installs a decoder for an image filter, taking precedence over the built in one. It is how a caller plugs in a JPEG decoder that reads what image/jpeg refuses, or a JPEG 2000 one.

Types

type Array

type Array = syntax.Array

Array is a PDF array.

type BBoxDevice

type BBoxDevice = gfx.BBoxDevice

BBoxDevice accumulates the bounding box of everything drawn.

func NewBBoxDevice

func NewBBoxDevice() *BBoxDevice

NewBBoxDevice returns a device that measures a page.

type BaseDevice

type BaseDevice = gfx.BaseDevice

BaseDevice implements Device with no-ops.

type BlendMode

type BlendMode = gfx.BlendMode

BlendMode is one of the sixteen blend modes of ISO 32000-1 11.3.5.

type Bool

type Bool = syntax.Bool

Bool is a PDF boolean.

type CMap

type CMap struct {
	Name  string
	WMode int
	// contains filtered or unexported fields
}

CMap maps byte codes to CIDs, ISO 32000-1 9.7.5. The same syntax is used by a ToUnicode CMap, where the values are Unicode rather than CIDs.

func (*CMap) Lookup

func (c *CMap) Lookup(code uint32) uint32

Lookup returns the CID a code maps to.

func (*CMap) Next

func (c *CMap) Next(s []byte) (code uint32, n int, cid uint32)

Next reads the code at the start of s and returns it, the number of bytes it used, and the CID it maps to.

func (*CMap) Text

func (c *CMap) Text(code uint32) string

Text returns the string a ToUnicode CMap maps a code to.

type Char

type Char struct {
	Code  uint32
	CID   uint32
	Bytes int
	// Width is the glyph advance in text space units of the font size, so
	// 1000 units per em has already been divided out for everything but a
	// Type3 font, whose advance goes through its own font matrix.
	Width float32
	// Space is true for a single byte code 32, which is what the word spacing
	// parameter applies to.
	Space bool
}

Char is one character code decoded from a string.

type ColorParams

type ColorParams = gfx.ColorParams

ColorParams are the rendering intent and the four flags that travel with every painting operation.

type ColorSpace

type ColorSpace = gfx.ColorSpace

ColorSpace is a color space, ISO 32000-1 8.6.

type DefaultColorSpaces

type DefaultColorSpaces = gfx.DefaultColorSpaces

DefaultColorSpaces is what the three device spaces mean.

type Device

type Device = gfx.Device

Device receives the drawing operations an interpreted content stream produces. Embed BaseDevice to pick up no-op implementations.

type Dict

type Dict = syntax.Dict

Dict is a PDF dictionary.

type Document

type Document struct {

	// GlyphCacheBytes bounds the rendered glyph masks the document keeps,
	// ImageCacheBytes the decoded images and ContentCacheOps the operands of
	// parsed content streams. Zero is the default, negative is no cache at all.
	GlyphCacheBytes int
	ImageCacheBytes int
	ContentCacheOps int
	// contains filtered or unexported fields
}

Document is an open PDF file.

A Document may be rendered from several goroutines at once, a Page each. Configuration - SetLayers, SetUsage, GlyphCacheBytes, ImageCacheBytes and ContentCacheOps - happens before they start, and Close after the last ends.

func Load

func Load(buf []byte, password string) (*Document, error)

Load reads a document from a buffer, which it takes ownership of.

func New

func New(f *syntax.File) *Document

New wraps an already parsed file.

func NewReader

func NewReader(r io.ReaderAt, size int64) (*Document, error)

NewReader reads size bytes from r.

func NewReaderPassword

func NewReaderPassword(r io.ReaderAt, size int64, password string) (*Document, error)

NewReaderPassword reads size bytes from r, decrypting with password.

func NewStream added in v0.2.0

func NewStream(r io.Reader) (*Document, error)

NewStream reads a document from a stream that cannot be seeked, which means reading all of it into memory first. A caller with an untrusted source bounds it with io.LimitReader.

func NewStreamPassword added in v0.2.0

func NewStreamPassword(r io.Reader, password string) (*Document, error)

NewStreamPassword is NewStream for an encrypted document.

func Open

func Open(name string) (*Document, error)

Open reads the named file.

func OpenPassword

func OpenPassword(name, password string) (*Document, error)

OpenPassword reads the named file, which is encrypted with password.

func (*Document) Close

func (d *Document) Close() error

Close releases the document and everything it has cached. It must not be called while a page is still rendering.

func (*Document) Err

func (d *Document) Err() []error

Err returns what has gone wrong so far, which a damaged file logs rather than fails on. It is safe to call while pages are rendering.

func (*Document) File

func (d *Document) File() *syntax.File

File returns the object layer underneath, for callers that want to read the document structure directly.

func (*Document) Layers

func (d *Document) Layers() []Layer

Layers returns the document's optional content groups and whether each is on, in the order the catalog lists them. It returns nothing for a document that has no optional content.

func (*Document) Metadata

func (d *Document) Metadata() Metadata

Metadata returns the document information dictionary.

func (*Document) NumPages

func (d *Document) NumPages() int

NumPages returns the number of pages.

func (*Document) Outline

func (d *Document) Outline() []Outline

Outline returns the document outline as the tree it is.

func (*Document) Page

func (d *Document) Page(i int) (*Page, error)

Page returns page i, counting from zero.

func (*Document) PageLabels

func (d *Document) PageLabels() []string

PageLabels returns what a viewer numbers each page with, ISO 32000-1 12.4.2, and nil for a document with no labels.

func (*Document) SetLayers

func (d *Document) SetLayers(layers []Layer)

SetLayers turns optional content groups on and off. Only the On field of each layer is read, and only layers this document declared are used, so the slice Layers returned can be edited and passed back.

func (*Document) SetSystemFonts

func (d *Document) SetSystemFonts(on bool)

SetSystemFonts chooses whether a font the file does not embed may be substituted with one the machine has. It is on by default and has to be set before the first page is rendered.

func (*Document) SetUsage

func (d *Document) SetUsage(u Usage)

SetUsage chooses what the document is rendered for, which decides both which optional content groups are on and which annotations are drawn. It undoes SetLayers. The default is UsageView.

func (*Document) Usage

func (d *Document) Usage() Usage

Usage returns what the document is being rendered for.

type DrawDevice

type DrawDevice = gfx.DrawDevice

DrawDevice renders into a raster.Pixmap.

func NewDrawDevice

func NewDrawDevice(doc *Document, dst *raster.Pixmap) *DrawDevice

NewDrawDevice returns a device that renders a page of doc into dst. The document holds the glyph cache and the errors a damaged file records.

type Font

type Font struct {
	Name  Name // /BaseFont, or /Name for a Type3 font
	Dict  Dict
	Type0 bool
	Type3 bool
	WMode int

	// Type3 fonts draw their glyphs with content streams.
	FontMatrix raster.Matrix
	CharProcs  Dict
	Resources  Dict
	// contains filtered or unexported fields
}

Font is a PDF font dictionary: what the interpreter needs to turn a string into positioned glyphs. The font program itself, and therefore the glyph outlines, arrive with the font engine.

func (*Font) BaseFont

func (ft *Font) BaseFont() string

BaseFont returns the base-14 name a substituted font resolved to.

func (*Font) Decode

func (ft *Font) Decode(s []byte) []Char

Decode splits a string into character codes.

func (*Font) EmBox

func (ft *Font) EmBox() (ascent, descent float32)

EmBox is how far the font's em box reaches above and below the baseline, in text space. The descriptor is preferred over the program.

func (*Font) FontName

func (ft *Font) FontName() string

FontName is the name the font goes by: /BaseFont, or /Name for a Type3.

func (*Font) Glyph

func (ft *Font) Glyph(c Char) int

Glyph is the index of the glyph a character selects, or -1 for none.

func (*Font) GlyphFace

func (ft *Font) GlyphFace(c Char, cur gfx.Font) (gfx.Font, int)

GlyphFace resolves a character to the glyph that draws it and the face it comes from, which is one the machine has when the character is outside what the stand in for a font the file did not embed can draw. cur is the face the run is already in, which keeps a space between two words of a script the stand in has no glyphs for from splitting the run in three.

func (*Font) GlyphName

func (ft *Font) GlyphName(code uint32) Name

GlyphName returns the name /Differences gave a code, or "".

func (*Font) GlyphNameOf

func (ft *Font) GlyphNameOf(c Char) string

GlyphNameOf returns what the font program calls the glyph a character selects, which is what a trace of the device calls it too.

func (*Font) Program

func (ft *Font) Program() *font.Font

Program returns the font program, embedded or substituted, or nil.

func (*Font) RunFace

func (ft *Font) RunFace(cs []Char) gfx.Font

RunFace is the face a whole shown string is drawn from: the one a character the stand in has no glyph for reaches for, so that a word is not half in one typeface and half in another. It is nil when the stand in covers the string.

func (*Font) RunGlyph

func (ft *Font) RunGlyph(dev Device, code int, m raster.Matrix, cs *ColorSpace, col []float32, alpha float32, depth int)

RunGlyph draws one glyph of a Type3 font into dev, by interpreting the content stream the glyph is.

func (*Font) Rune

func (ft *Font) Rune(c Char) rune

Rune returns the character a code stands for, for text extraction. Codes that map to nothing, and mappings that land on a control character, become the replacement character, which is what MuPDF shows and what a text extractor can recognize.

func (*Font) Substituted

func (ft *Font) Substituted() bool

Substituted reports a program standing in for a font the file left out.

func (*Font) Text

func (ft *Font) Text(c Char) string

Text is the characters a code stands for, more than one for a ligature.

type Function

type Function struct {
	Type   int
	Domain []float64
	Range  []float64
	// contains filtered or unexported fields
}

Function is a PDF function, ISO 32000-1 7.10: sampled, exponential, stitching, or a PostScript calculator.

func (*Function) Dict

func (f *Function) Dict() Dict

Dict returns the function dictionary.

func (*Function) Eval

func (f *Function) Eval(out []float64, in ...float64) []float64

Eval evaluates the function. The result is appended to out, which may be nil, so that a caller in a loop can reuse one buffer.

func (*Function) Eval1

func (f *Function) Eval1(out []float32, in float64) []float32

Eval1 evaluates a function of one input into a float32 slice, which is what color conversion works in.

func (*Function) NumOutputs

func (f *Function) NumOutputs() int

NumOutputs returns how many values Eval returns, or zero when the function only learns that from its own definition.

type Image

type Image struct {
	Width, Height int
	BPC           int
	CS            *ColorSpace
	// Mask is true for a stencil mask, which paints the fill color through
	// its one bit samples rather than carrying color of its own.
	Mask bool
	// Interpolate is the /Interpolate hint.
	Interpolate bool
	// Decode is the /Decode array, nil when the default applies.
	Decode []float64
	// SMask and StencilMask are the two ways an image carries transparency.
	SMask       *Image
	StencilMask *Image
	// ColorKey is the /Mask color key range, nil when there is none.
	ColorKey []int
	// contains filtered or unexported fields
}

Image is an image XObject or an inline image. The pixels are not decoded until a device asks for them.

func (*Image) ColorSpace

func (i *Image) ColorSpace() *ColorSpace

ColorSpace returns the space the samples are in, nil for a stencil mask.

func (*Image) Dict

func (i *Image) Dict() Dict

Dict returns the image dictionary.

func (*Image) MaskImage

func (i *Image) MaskImage() *Image

MaskImage returns the image that supplies this one's transparency, whether it came from /SMask or from a stencil /Mask. Both are drawn the same way: the mask clips, the image fills.

func (*Image) Pixels

func (i *Image) Pixels(cs *ColorSpace, shrink int) (*raster.Pixmap, error)

Pixels decodes the image into cs, halved shrink times, through the document's cache. A nil cs asks for the coverage of a stencil.

func (*Image) Pixmap

func (i *Image) Pixmap() (*raster.Pixmap, error)

Pixmap decodes the image into a pixmap in its own color space, with an alpha channel when it carries transparency. A stencil mask decodes to an alpha only pixmap, since it has no color of its own.

func (*Image) Size

func (i *Image) Size() (w, h int)

Size returns the image's own size in pixels.

func (*Image) Smooth

func (i *Image) Smooth() bool

Smooth reports the /Interpolate hint.

func (*Image) Stencil

func (i *Image) Stencil() bool

Stencil reports an image mask, which paints the fill color through its one bit samples and carries no color of its own.

type ImageDecoder

type ImageDecoder func(data []byte, parms Dict) (pix []byte, w, h, comps int, err error)

ImageDecoder turns the data of an image filter into interleaved eight bit samples, and reports the size and the number of components it produced.

type Integer

type Integer = syntax.Integer

Integer is a PDF integer.

type Kind

type Kind = gfx.Kind

Kind is the family a color space belongs to.

type Layer

type Layer struct {
	Name string
	On   bool
	// contains filtered or unexported fields
}

Layer is one optional content group: a part of a document that can be drawn or left out, with the name the file gives it.

type Link struct {
	// Rect is the area the link covers, in page space at 72 dots per inch.
	Rect raster.Rect
	// URI is where a link out of the document points.
	URI string
	// Page is the page a link inside the document goes to, and -1 otherwise.
	Page int
	// Point is where on that page it goes, in page space.
	Point raster.Point
}

Link is a link annotation: the area it covers and where following it goes.

type ListDevice

type ListDevice = gfx.ListDevice

ListDevice records what a page draws so that it can be drawn again.

func NewListDevice

func NewListDevice() *ListDevice

NewListDevice returns an empty display list.

type Metadata

type Metadata struct {
	Title    string
	Author   string
	Subject  string
	Keywords string
	Creator  string
	Producer string
	// Created and Modified are zero when the file gives no date.
	Created  time.Time
	Modified time.Time
}

Metadata is what the document says about itself, ISO 32000-1 14.3.3.

type Name

type Name = syntax.Name

Name is a PDF name.

type Object

type Object = syntax.Object

Object is a PDF object: Bool, Integer, Real, String, Name, Array, Dict, Ref or *Stream. A nil Object is null.

type Options

type Options struct {
	// ColorSpace is what the page composites in and what the result holds.
	// Nil means DeviceRGB. It must have one, three or four components.
	ColorSpace *ColorSpace

	// Alpha adds an alpha channel, and the page starts transparent, not white.
	Alpha bool

	// PixelLimit bounds the area a page may allocate, in pixels. Zero means
	// DefaultPixelLimit, negative means no limit.
	PixelLimit int

	// Strict turns the first error recorded while interpreting the page into
	// an error returned by Render. Without it a damaged page returns the part
	// that worked, and the errors are on the Document.
	Strict bool

	// Flatness is how far a flattened curve may stray from the true one, in
	// device pixels. Zero means the default.
	Flatness float32

	// Threads is how many goroutines rasterize one page. Zero and one mean
	// the page is drawn as it is interpreted; more means it is interpreted
	// once into a display list and then drawn into that many horizontal
	// bands at the same time. Negative means one for every processor.
	//
	// It is worth setting only for a page big enough that drawing it costs
	// more than reading it. Rendering several pages at once, a goroutine
	// each, scales better and needs nothing set here.
	//
	// A band clips what crosses its edge, and the crossing point rounds to
	// the rasterizer's 1/256 of a pixel, so a banded page may differ from
	// the same page drawn whole by one coverage unit along such an edge.
	Threads int
}

Options control rendering. A nil *Options means the defaults: DeviceRGB, no alpha channel, and a page composited onto white.

type Outline

type Outline struct {
	Title string
	// Page is the page the entry leads to, -1 otherwise, and Point where on it.
	Page  int
	Point raster.Point
	// URI is where an entry leading out of the document points.
	URI string
	// Open is whether the file asks for the entry to start expanded.
	Open bool
	// Children are the entries nested under this one.
	Children []Outline
}

Outline is one entry of the document outline, ISO 32000-1 12.3.3.

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page is one page of a document. Page is one page of a document, and is not safe for concurrent use: a goroutine that wants to render a page asks the Document for its own.

func (*Page) Bounds

func (p *Page) Bounds() raster.Rect

Bounds is the visible area of the page: the crop box inside the media box.

func (*Page) Contents

func (p *Page) Contents() []byte

Contents is the page content stream, the parts of a /Contents joined.

func (*Page) DeviceBounds

func (p *Page) DeviceBounds(dpi float64) raster.Rect

DeviceBounds returns the page rectangle in device space at a resolution, which is where a raster of the page begins and ends.

func (*Page) Dict

func (p *Page) Dict() Dict

Dict returns the page dictionary, with inherited attributes filled in.

func (*Page) HTML added in v0.2.0

func (p *Page) HTML() (string, error)

HTML returns the page as HTML.

func (*Page) Image

func (p *Page) Image() (*image.RGBA, error)

Image renders the page at the resolution its own content is in. A page with no text whose largest image covers half of it is cropped to that image.

func (*Page) ImageDPI

func (p *Page) ImageDPI(dpi float64) (*image.RGBA, error)

ImageDPI renders the page at a resolution in dots per inch.

func (*Page) ImageOptions

func (p *Page) ImageOptions(dpi float64, o *Options) (image.Image, error)

ImageOptions renders the page at a resolution, returning the standard library image type that matches the options: *image.Gray, *image.RGBA, *image.CMYK, or *image.RGBA for anything with an alpha channel.

func (p *Page) Links() []Link

Links returns the page's link annotations in the order the file lists them.

func (*Page) Matrix

func (p *Page) Matrix(dpi float64) raster.Matrix

Matrix returns the transform from PDF user space to device space at a given resolution: the y axis flips, the page rotation is applied, and the visible box moves to the origin. The order is the one MuPDF uses, so that traces taken from either carry the same numbers.

func (*Page) MediaBox

func (p *Page) MediaBox() raster.Rect

MediaBox returns the page boundary in points.

func (*Page) Number

func (p *Page) Number() int

Number returns the page index, counting from zero.

func (*Page) Render

func (p *Page) Render(ctm raster.Matrix, o *Options) (*raster.Pixmap, error)

Render draws the page into a new pixmap, with ctm mapping page space to device space. The pixmap covers the page bounds under ctm, rounded out, and records where that is in its X and Y.

A page that fails part way still returns what was drawn; the errors are on the Document unless Options.Strict asks for the first one back.

func (*Page) RenderTo

func (p *Page) RenderTo(dst draw.Image, ctm raster.Matrix, o *Options) error

RenderTo draws the page into a destination the caller owns, with ctm mapping page space to the destination's coordinates.

func (*Page) Resources

func (p *Page) Resources() Dict

Resources returns the page resource dictionary.

func (*Page) Rotate

func (p *Page) Rotate() int

Rotate returns the page rotation in degrees, a multiple of 90.

func (*Page) Run

func (p *Page) Run(dev Device, ctm raster.Matrix) error

Run interprets the page into a device, with ctm mapping page space to device space. Both the contents and the annotation appearances are drawn.

func (*Page) RunAnnotations

func (p *Page) RunAnnotations(dev Device, ctm raster.Matrix)

RunAnnotations draws the appearance streams of the page annotations. The widgets come last, after everything else on the page, which is the order MuPDF draws them in and the one a form on top of its own background needs.

func (*Page) RunContents

func (p *Page) RunContents(dev Device, ctm raster.Matrix)

RunContents interprets the page content stream only.

func (*Page) SVG

func (p *Page) SVG() (string, error)

SVG returns the page as SVG.

func (*Page) StructuredText

func (p *Page) StructuredText() (*TextPage, error)

StructuredText returns the page's text with the box every character, line and block occupies, in page space at 72 dots per inch.

func (*Page) StructuredTextOptions

func (p *Page) StructuredTextOptions(o *TextOptions) (*TextPage, error)

StructuredTextOptions is StructuredText with options.

func (*Page) Text

func (p *Page) Text() (string, error)

Text is the page's text: a newline after a line, a blank line after a block.

func (*Page) UserUnit

func (p *Page) UserUnit() float64

UserUnit is the /UserUnit scale, which is 1 for all but very large pages.

func (*Page) WriteHTML added in v0.2.0

func (p *Page) WriteHTML(w io.Writer) error

WriteHTML writes the page as HTML: the text where it was drawn, in the face and the colour it was drawn with.

func (*Page) WriteSVG

func (p *Page) WriteSVG(w io.Writer) error

WriteSVG writes the page as SVG. Paths, text and images come out as themselves; a shading and a soft mask are rasterized.

type Quad

type Quad = gfx.Quad

Quad is the four corners of what a character occupies.

type Real

type Real = syntax.Real

Real is a PDF real number.

type Ref

type Ref = syntax.Ref

Ref is an indirect reference.

type Shade

type Shade struct {
	Type int // 1 function, 2 axial, 3 radial, 4-7 mesh
	CS   *ColorSpace
	// Matrix is the pattern matrix when the shading came from a pattern, and
	// the identity when it came from sh.
	Matrix raster.Matrix
	// BBox is the shading's bounding box in its own space, empty for none.
	BBox       raster.Rect
	Background []float64
	Coords     []float64
	Domain     []float64
	Extend     [2]bool
	Function   []*Function

	// FuncMatrix, XDivs and YDivs describe a type 1 shading, whose function
	// is sampled over a rectangle of its own space.
	FuncMatrix   raster.Matrix
	XDivs, YDivs int
	// contains filtered or unexported fields
}

Shade is a shading dictionary: the sh operator paints one directly, and a shading pattern paints one through a path.

func (*Shade) Bounds

func (s *Shade) Bounds() raster.Rect

Bounds returns the shading's own bounding box, empty when it has none.

func (*Shade) ColorSpace

func (s *Shade) ColorSpace() *ColorSpace

ColorSpace returns the space the shading's colors are in.

func (*Shade) Coord6

func (s *Shade) Coord6() [6]float32

Coord6 returns the /Coords of an axial or radial shading, padded to the six numbers those two types use.

func (*Shade) Dict

func (s *Shade) Dict() Dict

Dict returns the shading dictionary.

func (*Shade) Domain4

func (s *Shade) Domain4() [4]float32

Domain4 is the /Domain of a type 1 shading, the unit square by default.

func (*Shade) Shader

func (s *Shade) Shader(model raster.Model, ctm raster.Matrix, box raster.Rect) raster.Shader

Shader prepares the shading to be painted into a destination of the given model, under ctm and over box, and returns nil when nothing is painted.

func (*Shade) Transform

func (s *Shade) Transform() raster.Matrix

Transform returns the pattern matrix, which maps the shading's own space into the space the ctm a device is given starts from.

type Stream

type Stream = syntax.Stream

Stream is a PDF stream.

type String

type String = syntax.String

String is a PDF string.

type Text

type Text = gfx.Text

Text is what a text showing operator, or a run of them, hands a device.

type TextBlock

type TextBlock = gfx.TextBlock

TextBlock is a paragraph of text, or one image.

type TextChar

type TextChar = gfx.TextChar

TextChar is one character where it was drawn.

type TextItem

type TextItem = gfx.TextItem

TextItem is one glyph placed by a text showing operator.

type TextLine

type TextLine = gfx.TextLine

TextLine is a run of characters along one baseline.

type TextOptions

type TextOptions = gfx.TextOptions

TextOptions configure what StructuredTextOptions collects.

type TextPage

type TextPage = gfx.TextPage

TextPage is a page's text: blocks of lines of characters.

type TextSpan

type TextSpan = gfx.TextSpan

TextSpan is a run of glyphs from one font under one text matrix.

type TraceDevice

type TraceDevice struct {
	BaseDevice
	// contains filtered or unexported fields
}

TraceDevice writes every device call as XML, in the format mutool trace produces, so that the two can be compared without a rasterizer in the way.

func NewTraceDevice

func NewTraceDevice(w io.Writer) *TraceDevice

NewTraceDevice returns a device that writes to w.

func (*TraceDevice) BeginGroup

func (d *TraceDevice) BeginGroup(area raster.Rect, cs *ColorSpace, isolated, knockout bool, blend BlendMode, alpha float32)

BeginGroup implements Device.

func (*TraceDevice) BeginLayer

func (d *TraceDevice) BeginLayer(name string)

BeginLayer implements Device.

func (*TraceDevice) BeginMask

func (d *TraceDevice) BeginMask(area raster.Rect, luminosity bool, cs *ColorSpace, backdrop []float32, cp ColorParams)

BeginMask implements Device.

func (*TraceDevice) BeginTile

func (d *TraceDevice) BeginTile(area, view raster.Rect, xstep, ystep float32, ctm raster.Matrix) int

BeginTile implements Device.

func (*TraceDevice) ClipImageMask

func (d *TraceDevice) ClipImageMask(img gfx.Image, ctm raster.Matrix, scissor raster.Rect)

ClipImageMask implements Device.

func (*TraceDevice) ClipPath

func (d *TraceDevice) ClipPath(p *raster.Path, evenOdd bool, ctm raster.Matrix, scissor raster.Rect)

ClipPath implements Device.

func (*TraceDevice) ClipStrokePath

func (d *TraceDevice) ClipStrokePath(p *raster.Path, s *raster.Stroke, ctm raster.Matrix, scissor raster.Rect)

ClipStrokePath implements Device.

func (*TraceDevice) ClipStrokeText

func (d *TraceDevice) ClipStrokeText(t *Text, s *raster.Stroke, ctm raster.Matrix, scissor raster.Rect)

ClipStrokeText implements Device.

func (*TraceDevice) ClipText

func (d *TraceDevice) ClipText(t *Text, ctm raster.Matrix, scissor raster.Rect)

ClipText implements Device.

func (*TraceDevice) Close

func (d *TraceDevice) Close() error

Close flushes the output.

func (*TraceDevice) EndGroup

func (d *TraceDevice) EndGroup()

EndGroup implements Device.

func (*TraceDevice) EndLayer

func (d *TraceDevice) EndLayer()

EndLayer implements Device.

func (*TraceDevice) EndMask

func (d *TraceDevice) EndMask(transfer *[256]uint8)

EndMask implements Device.

func (*TraceDevice) EndTile

func (d *TraceDevice) EndTile()

EndTile implements Device.

func (*TraceDevice) FillImage

func (d *TraceDevice) FillImage(img gfx.Image, ctm raster.Matrix, alpha float32, cp ColorParams)

FillImage implements Device.

func (*TraceDevice) FillImageMask

func (d *TraceDevice) FillImageMask(img gfx.Image, ctm raster.Matrix, cs *ColorSpace, c []float32, alpha float32, cp ColorParams)

FillImageMask implements Device.

func (*TraceDevice) FillPath

func (d *TraceDevice) FillPath(p *raster.Path, evenOdd bool, ctm raster.Matrix, cs *ColorSpace, c []float32, alpha float32, cp ColorParams)

FillPath implements Device.

func (*TraceDevice) FillShade

func (d *TraceDevice) FillShade(shade gfx.Shade, ctm raster.Matrix, alpha float32, cp ColorParams)

FillShade implements Device.

func (*TraceDevice) FillText

func (d *TraceDevice) FillText(t *Text, ctm raster.Matrix, cs *ColorSpace, c []float32, alpha float32, cp ColorParams)

FillText implements Device.

func (*TraceDevice) IgnoreText

func (d *TraceDevice) IgnoreText(t *Text, ctm raster.Matrix)

IgnoreText implements Device.

func (*TraceDevice) PopClip

func (d *TraceDevice) PopClip()

PopClip implements Device.

func (*TraceDevice) SetDefaultColorSpaces

func (d *TraceDevice) SetDefaultColorSpaces(cs *DefaultColorSpaces)

SetDefaultColorSpaces implements Device.

func (*TraceDevice) StrokePath

func (d *TraceDevice) StrokePath(p *raster.Path, s *raster.Stroke, ctm raster.Matrix, cs *ColorSpace, c []float32, alpha float32, cp ColorParams)

StrokePath implements Device.

func (*TraceDevice) StrokeText

func (d *TraceDevice) StrokeText(t *Text, s *raster.Stroke, ctm raster.Matrix, cs *ColorSpace, c []float32, alpha float32, cp ColorParams)

StrokeText implements Device.

type Usage

type Usage int

Usage is what a document is being rendered for. Optional content groups and annotations may be meant for the screen, for paper, or for neither; ISO 32000-1 calls these the three events of a usage application dictionary.

const (
	UsageView Usage = iota
	UsagePrint
	UsageExport
)

The three events.

Jump to

Keyboard shortcuts

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