pdf

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 the default bound, in operands, of a document's parsed content cache.

View Source
const DefaultImageCacheBytes = 1 << 26

DefaultImageCacheBytes is the default size of a document's decoded image cache.

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.

func RegisterRowDecoder added in v0.3.0

func RegisterRowDecoder(filter Name, dec RowDecoder)

RegisterRowDecoder installs a row decoder for an image filter, taking precedence over a whole one. Only DCTDecode is read through it: an image is then decoded a band of rows at a time, whole or in bands.

pdf.RegisterRowDecoder("DCTDecode", func(b []byte, _ pdf.Dict) (pdf.ImageRows, error) {
	r, err := jpegn.NewRowReader(b)
	if err != nil {
		return nil, err
	}
	return r, nil
})

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, or for a ToUnicode CMap to text, ISO 32000-1 9.7.5.

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 returns the code at the start of s, its length in bytes, and its CID.

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.
	Width float32
	// Space is true for a single byte code 32.
	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, ImageCacheBytes and ContentCacheOps bound the document's
	// caches; zero is the default, negative is no cache.
	GlyphCacheBytes int
	ImageCacheBytes int
	ContentCacheOps int
	// contains filtered or unexported fields
}

Document is an open PDF file, safe to render from several goroutines at once.

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, all of it into memory.

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, decrypting with password.

func (*Document) Close

func (d *Document) Close() error

Close releases the document and everything it has cached.

func (*Document) Err

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

Err returns the errors recorded so far.

func (*Document) File

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

File returns the object layer underneath.

func (*Document) Layers

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

Layers returns the document's optional content groups in catalog order and whether each is on.

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 the label of each page, ISO 32000-1 12.4.2, or nil for none.

func (*Document) SetLayers

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

SetLayers turns optional content groups on and off by the On field of each layer.

func (*Document) SetSystemFonts

func (d *Document) SetSystemFonts(on bool)

SetSystemFonts chooses whether a font the file does not embed may be substituted with a system font.

func (*Document) SetUsage

func (d *Document) SetUsage(u Usage)

SetUsage chooses what the document is rendered for, UsageView by default.

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, read for turning a string into positioned glyphs.

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 returns the reach of the font's em box above and below the baseline, in text space.

func (*Font) FontName

func (ft *Font) FontName() string

FontName returns /BaseFont, or /Name for a Type3 font.

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, preferring cur, the face the run is already in.

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 the font program's name for the glyph a character selects.

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 returns the fallback face a whole shown string is drawn from, or nil.

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.

func (*Font) Rune

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

Rune returns the character a code stands for, or the replacement character.

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, appending the result to out, which may be nil.

func (*Function) Eval1

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

Eval1 evaluates a function of one input into a float32 slice.

func (*Function) NumOutputs

func (f *Function) NumOutputs() int

NumOutputs returns how many values Eval returns, or zero when only the definition says.

type Image

type Image struct {
	Width, Height int
	BPC           int
	CS            *ColorSpace
	// Mask is true for a stencil mask.
	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, decoded on demand.

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 /SMask or stencil /Mask image that supplies this one's transparency.

func (*Image) PixelRows added in v0.3.0

func (i *Image) PixelRows(dst *ColorSpace, shrink int) (*gfx.PixelRows, bool)

PixelRows implements gfx.RowImage: the pixmap Pixels builds, handed out a row at a time, for an image with no mask or color key whose samples source can read.

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.

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.

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 ImageRows added in v0.3.0

type ImageRows interface {
	Width() int
	Height() int
	ColorModel() stdcolor.Model
	Next() ([]byte, int, error)
	Close()
}

ImageRows hands out the rows of a decoded image a band at a time, top first, RowBytes apart: Gray, RGBA or CMYK, as jpegn's RowReader does.

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 and 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 the document information, 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 the target of an entry leading out of the document.
	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, not safe for concurrent use.

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.

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) ImageBands added in v0.3.0

func (p *Page) ImageBands(dpi float64, rows int, fn func(*image.RGBA) error) error

ImageBands renders the page as ImageDPI does, rows at a time, and hands each band to fn in order from the top. A band's Rect is its place in the image ImageDPI returns, valid only until fn returns, and a dpi of zero or less is the resolution and the crop of Image. The pixel limit bounds a band, not the page. An error from fn stops the render and is returned.

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 into the standard library image type that matches the options.

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, with the y axis flipped, the rotation applied and the box at the origin.

func (*Page) MediaBox

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

MediaBox returns the page boundary in points.

func (*Page) NaturalDPI added in v0.2.8

func (p *Page) NaturalDPI() float64

NaturalDPI is the resolution Image renders the page at.

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 covering the page bounds under ctm, with ctm mapping page space to device space.

func (*Page) RenderBands added in v0.3.0

func (p *Page) RenderBands(ctm raster.Matrix, o *Options, rows int, fn func(*raster.Pixmap) error) error

RenderBands draws the page as Render does, rows at a time, and hands each band to fn in order from the top: a pixmap whose X and Y are its place in device space, valid only until fn returns. The pixel limit bounds a band, not the page, and rows of zero or less is as many as it allows. An error from fn stops the render and is returned.

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 contents and annotation appearances into a device, with ctm mapping page space to device space.

func (*Page) RunAnnotations

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

RunAnnotations draws the appearance streams of the page annotations, widgets last as MuPDF does.

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.

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 RowDecoder added in v0.3.0

type RowDecoder func(data []byte, parms Dict) (ImageRows, error)

RowDecoder starts decoding the data of an image filter a band of rows at a time.

type Shade

type Shade struct {
	Type int // 1 function, 2 axial, 3 radial, 4-7 mesh
	CS   *ColorSpace
	// Matrix is the pattern matrix, the identity for 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.
	FuncMatrix   raster.Matrix
	XDivs, YDivs int
	// contains filtered or unexported fields
}

Shade is a shading dictionary, painted by the sh operator or a shading pattern.

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 six numbers.

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, from the shading's space to the space the device ctm 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 names the event a document is rendered for, ISO 32000-1 8.11.4.4.

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