contentstream

package
v0.0.0-...-1effa6f Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: AGPL-3.0, AGPL-3.0-only Imports: 14 Imported by: 6

Documentation

Overview

Package contentstream provides functionality for parsing and creating content streams for PDF files.

For processing and manipulating content streams, it allows parse the content stream into a list of operands that can then be processed further for rendering or extraction of information. The ContentStreamProcessor offers a basic engine for processing the content stream and can be used to render or modify the contents.

For creating content streams, see NewContentCreator. It allows adding multiple operands and then can be converted to a string for embedding in a PDF file.

The contentstream package uses the core and model packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOperand specifies that invalid operands have been encountered
	// while parsing the content stream.
	ErrInvalidOperand = errors.New("invalid operand")
)

Functions

This section is empty.

Types

type ContentCreator

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

ContentCreator is a builder for PDF content streams.

func NewContentCreator

func NewContentCreator() *ContentCreator

NewContentCreator returns a new initialized ContentCreator.

func (*ContentCreator) AddOperand

AddOperand adds a specified operand.

func (*ContentCreator) Add_B

func (cc *ContentCreator) Add_B() *ContentCreator

Add_B appends 'B' operand to the content stream: Fill and then stroke the path (nonzero winding number rule).

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_BMC

func (cc *ContentCreator) Add_BMC(tag core.PdfObjectName) *ContentCreator

Add_BMC appends 'BMC' operand to the content stream: Begins a marked-content sequence terminated by a balancing EMC operator. `tag` shall be a name object indicating the role or significance of the sequence.

See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).

func (*ContentCreator) Add_BT

func (cc *ContentCreator) Add_BT() *ContentCreator

Add_BT appends 'BT' operand to the content stream: Begin text.

See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).

func (*ContentCreator) Add_B_starred

func (cc *ContentCreator) Add_B_starred() *ContentCreator

Add_B_starred appends 'B*' operand to the content stream: Fill and then stroke the path (even-odd rule).

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_CS

func (cc *ContentCreator) Add_CS(name core.PdfObjectName) *ContentCreator

Add_CS appends 'CS' operand to the content stream: Set the current colorspace for stroking operations.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_Do

func (cc *ContentCreator) Add_Do(name core.PdfObjectName) *ContentCreator

Add_Do adds 'Do' operation to the content stream: Displays an XObject (image or form) specified by `name`.

See section 8.8 "External Objects" and Table 87 (pp. 209-220 PDF32000_2008).

func (*ContentCreator) Add_EMC

func (cc *ContentCreator) Add_EMC() *ContentCreator

Add_EMC appends 'EMC' operand to the content stream: Ends a marked-content sequence.

See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).

func (*ContentCreator) Add_ET

func (cc *ContentCreator) Add_ET() *ContentCreator

Add_ET appends 'ET' operand to the content stream: End text.

See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).

func (*ContentCreator) Add_G

func (cc *ContentCreator) Add_G(gray float64) *ContentCreator

Add_G appends 'G' operand to the content stream: Set the stroking colorspace to DeviceGray and sets the gray level (0-1).

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_J

func (cc *ContentCreator) Add_J(lineCapStyle string) *ContentCreator

Add_J adds 'J' operand to the content stream: Set the line cap style (graphics state).

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_K

func (cc *ContentCreator) Add_K(c, m, y, k float64) *ContentCreator

Add_K appends 'K' operand to the content stream: Set the stroking colorspace to DeviceCMYK and sets the c,m,y,k color (0-1 each component).

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_M

func (cc *ContentCreator) Add_M(miterlimit float64) *ContentCreator

Add_M adds 'M' operand to the content stream: Set the miter limit (graphics state).

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_Q

func (cc *ContentCreator) Add_Q() *ContentCreator

Add_Q adds 'Q' operand to the content stream: Pops the most recently stored state from the stack.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_RG

func (cc *ContentCreator) Add_RG(r, g, b float64) *ContentCreator

Add_RG appends 'RG' operand to the content stream: Set the stroking colorspace to DeviceRGB and sets the r,g,b colors (0-1 each).

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_S

func (cc *ContentCreator) Add_S() *ContentCreator

Add_S appends 'S' operand to the content stream: Stroke the path.

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_SC

func (cc *ContentCreator) Add_SC(c ...float64) *ContentCreator

Add_SC appends 'SC' operand to the content stream: Set color for stroking operations. Input: c1, ..., cn.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_SCN

func (cc *ContentCreator) Add_SCN(c ...float64) *ContentCreator

Add_SCN appends 'SCN' operand to the content stream: Same as SC but supports more colorspaces.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_SCN_pattern

func (cc *ContentCreator) Add_SCN_pattern(name core.PdfObjectName, c ...float64) *ContentCreator

Add_SCN_pattern appends 'SCN' operand to the content stream for pattern `name`: SCN with name attribute (for pattern). Syntax: c1 ... cn name SCN.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_TD

func (cc *ContentCreator) Add_TD(tx, ty float64) *ContentCreator

Add_TD appends 'TD' operand to the content stream: Move to start of next line with offset (`tx`, `ty`).

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*ContentCreator) Add_TJ

func (cc *ContentCreator) Add_TJ(vals ...core.PdfObject) *ContentCreator

Add_TJ appends 'TJ' operand to the content stream: Show one or more text string. Array of numbers (displacement) and strings.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*ContentCreator) Add_TL

func (cc *ContentCreator) Add_TL(leading float64) *ContentCreator

Add_TL appends 'TL' operand to the content stream: Set leading.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_Tc

func (cc *ContentCreator) Add_Tc(charSpace float64) *ContentCreator

Add_Tc appends 'Tc' operand to the content stream: Set character spacing.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_Td

func (cc *ContentCreator) Add_Td(tx, ty float64) *ContentCreator

Add_Td appends 'Td' operand to the content stream: Move to start of next line with offset (`tx`, `ty`).

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*ContentCreator) Add_Tf

func (cc *ContentCreator) Add_Tf(fontName core.PdfObjectName, fontSize float64) *ContentCreator

Add_Tf appends 'Tf' operand to the content stream: Set font and font size specified by font resource `fontName` and `fontSize`.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_Tj

func (cc *ContentCreator) Add_Tj(textstr core.PdfObjectString) *ContentCreator

Add_Tj appends 'Tj' operand to the content stream: Show a text string.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*ContentCreator) Add_Tm

func (cc *ContentCreator) Add_Tm(a, b, c, d, e, f float64) *ContentCreator

Add_Tm appends 'Tm' operand to the content stream: Set the text line matrix.

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*ContentCreator) Add_Tr

func (cc *ContentCreator) Add_Tr(render int64) *ContentCreator

Add_Tr appends 'Tr' operand to the content stream: Set text rendering mode.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_Ts

func (cc *ContentCreator) Add_Ts(rise float64) *ContentCreator

Add_Ts appends 'Ts' operand to the content stream: Set text rise.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_Tstar

func (cc *ContentCreator) Add_Tstar() *ContentCreator

Add_Tstar appends 'T*' operand to the content stream: Move to the start of next line.

See section 9.4.2 "Text Positioning Operators" and Table 108 (pp. 257-258 PDF32000_2008).

func (*ContentCreator) Add_Tw

func (cc *ContentCreator) Add_Tw(wordSpace float64) *ContentCreator

Add_Tw appends 'Tw' operand to the content stream: Set word spacing.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_Tz

func (cc *ContentCreator) Add_Tz(scale float64) *ContentCreator

Add_Tz appends 'Tz' operand to the content stream: Set horizontal scaling.

See section 9.3 "Text State Parameters and Operators" and Table 105 (pp. 251-252 PDF32000_2008).

func (*ContentCreator) Add_W

func (cc *ContentCreator) Add_W() *ContentCreator

Add_W appends 'W' operand to the content stream: Modify the current clipping path by intersecting with the current path (nonzero winding rule).

See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).

func (*ContentCreator) Add_W_starred

func (cc *ContentCreator) Add_W_starred() *ContentCreator

Add_W_starred appends 'W*' operand to the content stream: Modify the current clipping path by intersecting with the current path (even odd rule).

See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).

func (*ContentCreator) Add_b

func (cc *ContentCreator) Add_b() *ContentCreator

Add_b appends 'b' operand to the content stream: Close, fill and then stroke the path (nonzero winding number rule).

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_b_starred

func (cc *ContentCreator) Add_b_starred() *ContentCreator

Add_b_starred appends 'b*' operand to the content stream: Close, fill and then stroke the path (even-odd winding number rule).

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_c

func (cc *ContentCreator) Add_c(x1, y1, x2, y2, x3, y3 float64) *ContentCreator

Add_c adds 'c' operand to the content stream: Append a Bezier curve to the current path from the current point to (x3,y3) with (x1,x1) and (x2,y2) as control points.

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Add_cm

func (cc *ContentCreator) Add_cm(a, b, c, d, e, f float64) *ContentCreator

Add_cm adds 'cm' operation to the content stream: Modifies the current transformation matrix (ctm) of the graphics state.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_cs

func (cc *ContentCreator) Add_cs(name core.PdfObjectName) *ContentCreator

Add_cs appends 'cs' operand to the content stream: Same as CS but for non-stroking operations.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_d

func (cc *ContentCreator) Add_d(dashArray []int64, dashPhase int64) *ContentCreator

Add_d adds 'd' operand to the content stream: Set the line dash pattern.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_f

func (cc *ContentCreator) Add_f() *ContentCreator

Add_f appends 'f' operand to the content stream: Fill the path using the nonzero winding number rule to determine fill region.

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_f_starred

func (cc *ContentCreator) Add_f_starred() *ContentCreator

Add_f_starred appends 'f*' operand to the content stream. f*: Fill the path using the even-odd rule to determine fill region.

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_g

func (cc *ContentCreator) Add_g(gray float64) *ContentCreator

Add_g appends 'g' operand to the content stream: Same as G but used for nonstroking operations.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_gs

func (cc *ContentCreator) Add_gs(dictName core.PdfObjectName) *ContentCreator

Add_gs adds 'gs' operand to the content stream: Set the graphics state.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_h

func (cc *ContentCreator) Add_h() *ContentCreator

Add_h appends 'h' operand to the content stream: Close the current subpath by adding a line between the current position and the starting position.

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Add_i

func (cc *ContentCreator) Add_i(flatness float64) *ContentCreator

Add_i adds 'i' operand to the content stream: Set the flatness tolerance in the graphics state.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_j

func (cc *ContentCreator) Add_j(lineJoinStyle string) *ContentCreator

Add_j adds 'j' operand to the content stream: Set the line join style (graphics state).

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_k

func (cc *ContentCreator) Add_k(c, m, y, k float64) *ContentCreator

Add_k appends 'k' operand to the content stream: Same as K but used for nonstroking operations.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_l

func (cc *ContentCreator) Add_l(x, y float64) *ContentCreator

Add_l adds 'l' operand to the content stream: Append a straight line segment from the current point to (x,y).

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Add_m

func (cc *ContentCreator) Add_m(x, y float64) *ContentCreator

Add_m adds 'm' operand to the content stream: Move the current point to (x,y).

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Add_n

func (cc *ContentCreator) Add_n() *ContentCreator

Add_n appends 'n' operand to the content stream: End the path without filling or stroking.

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_q

func (cc *ContentCreator) Add_q() *ContentCreator

Add_q adds 'q' operand to the content stream: Pushes the current graphics state on the stack.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_quote

func (cc *ContentCreator) Add_quote(textstr core.PdfObjectString) *ContentCreator

Add_quote appends "'" operand to the content stream: Move to next line and show a string.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*ContentCreator) Add_quotes

func (cc *ContentCreator) Add_quotes(textstr core.PdfObjectString, aw, ac float64) *ContentCreator

Add_quotes appends "”" operand to the content stream: Move to next line and show a string, using `aw` and `ac` as word and character spacing respectively.

See section 9.4.3 "Text Showing Operators" and Table 209 (pp. 258-259 PDF32000_2008).

func (*ContentCreator) Add_re

func (cc *ContentCreator) Add_re(x, y, width, height float64) *ContentCreator

Add_re appends 're' operand to the content stream: Append a rectangle to the current path as a complete subpath, with lower left corner (x,y).

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Add_rg

func (cc *ContentCreator) Add_rg(r, g, b float64) *ContentCreator

Add_rg appends 'rg' operand to the content stream: Same as RG but used for nonstroking operations.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_ri

func (cc *ContentCreator) Add_ri(intent core.PdfObjectName) *ContentCreator

Add_ri adds 'ri' operand to the content stream, which sets the color rendering intent.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_s

func (cc *ContentCreator) Add_s() *ContentCreator

Add_s appends 's' operand to the content stream: Close and stroke the path.

See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).

func (*ContentCreator) Add_scn

func (cc *ContentCreator) Add_scn(c ...float64) *ContentCreator

Add_scn appends 'scn' operand to the content stream: Same as SC but for nonstroking operations.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_scn_pattern

func (cc *ContentCreator) Add_scn_pattern(name core.PdfObjectName, c ...float64) *ContentCreator

Add_scn_pattern appends 'scn' operand to the content stream for pattern `name`: scn with name attribute (for pattern). Syntax: c1 ... cn name scn.

See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).

func (*ContentCreator) Add_sh

func (cc *ContentCreator) Add_sh(name core.PdfObjectName) *ContentCreator

Add_sh appends 'sh' operand to the content stream: Paints the shape and colour shading described by a shading dictionary specified by `name`, subject to the current clipping path

See section 8.7.4 "Shading Patterns" and Table 77 (p. 190 PDF32000_2008).

func (*ContentCreator) Add_v

func (cc *ContentCreator) Add_v(x2, y2, x3, y3 float64) *ContentCreator

Add_v appends 'v' operand to the content stream: Append a Bezier curve to the current path from the current point to (x3,y3) with the current point and (x2,y2) as control points.

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Add_w

func (cc *ContentCreator) Add_w(lineWidth float64) *ContentCreator

Add_w adds 'w' operand to the content stream, which sets the line width.

See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).

func (*ContentCreator) Add_y

func (cc *ContentCreator) Add_y(x1, y1, x3, y3 float64) *ContentCreator

Add_y appends 'y' operand to the content stream: Append a Bezier curve to the current path from the current point to (x3,y3) with (x1, y1) and (x3,y3) as control points.

See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).

func (*ContentCreator) Bytes

func (cc *ContentCreator) Bytes() []byte

Bytes converts the content stream operations to a content stream byte presentation, i.e. the kind that can be stored as a PDF stream or string format.

func (*ContentCreator) Operations

func (cc *ContentCreator) Operations() *ContentStreamOperations

Operations returns the list of operations.

func (*ContentCreator) RotateDeg

func (cc *ContentCreator) RotateDeg(angle float64) *ContentCreator

RotateDeg applies a rotation to the transformation matrix.

func (*ContentCreator) Scale

func (cc *ContentCreator) Scale(sx, sy float64) *ContentCreator

Scale applies x-y scaling to the transformation matrix.

func (*ContentCreator) SetNonStrokingColor

func (cc *ContentCreator) SetNonStrokingColor(color model.PdfColor) *ContentCreator

SetNonStrokingColor sets the non-stroking `color` where color can be one of PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.

func (*ContentCreator) SetStrokingColor

func (cc *ContentCreator) SetStrokingColor(color model.PdfColor) *ContentCreator

SetStrokingColor sets the stroking `color` where color can be one of PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.

func (*ContentCreator) String

func (cc *ContentCreator) String() string

String is same as Bytes() except returns as a string for convenience.

func (*ContentCreator) Translate

func (cc *ContentCreator) Translate(tx, ty float64) *ContentCreator

Translate applies a simple x-y translation to the transformation matrix.

func (*ContentCreator) Wrap

func (cc *ContentCreator) Wrap()

Wrap ensures that the contentstream is wrapped within a balanced q ... Q expression.

type ContentStreamInlineImage

type ContentStreamInlineImage struct {
	BitsPerComponent core.PdfObject
	ColorSpace       core.PdfObject
	Decode           core.PdfObject
	DecodeParms      core.PdfObject
	Filter           core.PdfObject
	Height           core.PdfObject
	ImageMask        core.PdfObject
	Intent           core.PdfObject
	Interpolate      core.PdfObject
	Width            core.PdfObject
	// contains filtered or unexported fields
}

ContentStreamInlineImage is a representation of an inline image in a Content stream. Everything between the BI and EI operands. ContentStreamInlineImage implements the core.PdfObject interface although strictly it is not a PDF object.

func NewInlineImageFromImage

func NewInlineImageFromImage(img model.Image, encoder core.StreamEncoder) (*ContentStreamInlineImage, error)

NewInlineImageFromImage makes a new content stream inline image object from an image.

func (*ContentStreamInlineImage) GetColorSpace

func (img *ContentStreamInlineImage) GetColorSpace(resources *model.PdfPageResources) (model.PdfColorspace, error)

GetColorSpace returns the colorspace of the inline image.

func (*ContentStreamInlineImage) GetEncoder

func (img *ContentStreamInlineImage) GetEncoder() (core.StreamEncoder, error)

GetEncoder returns the encoder of the inline image.

func (*ContentStreamInlineImage) IsMask

func (img *ContentStreamInlineImage) IsMask() (bool, error)

IsMask checks if an image is a mask. The image mask entry in the image dictionary specifies that the image data shall be used as a stencil mask for painting in the current color. The mask data is 1bpc, grayscale.

func (*ContentStreamInlineImage) String

func (img *ContentStreamInlineImage) String() string

func (*ContentStreamInlineImage) ToImage

func (img *ContentStreamInlineImage) ToImage(resources *model.PdfPageResources) (*model.Image, error)

ToImage exports the inline image to Image which can be transformed or exported easily. Page resources are needed to look up colorspace information.

func (*ContentStreamInlineImage) WriteString

func (img *ContentStreamInlineImage) WriteString() string

WriteString outputs the object as it is to be written to file.

type ContentStreamOperation

type ContentStreamOperation struct {
	Params  []core.PdfObject
	Operand string
}

ContentStreamOperation represents an operation in PDF contentstream which consists of an operand and parameters.

type ContentStreamOperations

type ContentStreamOperations []*ContentStreamOperation

ContentStreamOperations is a slice of ContentStreamOperations.

func (*ContentStreamOperations) Bytes

func (ops *ContentStreamOperations) Bytes() []byte

Bytes converts a set of content stream operations to a content stream byte presentation, i.e. the kind that can be stored as a PDF stream or string format.

func (*ContentStreamOperations) String

func (ops *ContentStreamOperations) String() string

String returns `ops.Bytes()` as a string.

func (*ContentStreamOperations) WrapIfNeeded

func (ops *ContentStreamOperations) WrapIfNeeded() *ContentStreamOperations

WrapIfNeeded wraps the entire contents within q ... Q. If unbalanced, then adds extra Qs at the end. Only does if needed. Ensures that when adding new content, one start with all states in the default condition.

type ContentStreamParser

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

ContentStreamParser represents a content stream parser for parsing content streams in PDFs.

func NewContentStreamParser

func NewContentStreamParser(contentStr string) *ContentStreamParser

NewContentStreamParser creates a new instance of the content stream parser from an input content stream string.

func (*ContentStreamParser) ExtractText deprecated

func (csp *ContentStreamParser) ExtractText() (string, error)

ExtractText parses and extracts all text data in content streams and returns as a string. Does not take into account Encoding table, the output is simply the character codes.

Deprecated: More advanced text extraction is offered in package extractor with character encoding support.

func (*ContentStreamParser) Parse

Parse parses all commands in content stream, returning a list of operation data.

func (*ContentStreamParser) ParseInlineImage

func (csp *ContentStreamParser) ParseInlineImage() (*ContentStreamInlineImage, error)

ParseInlineImage parses an inline image from a content stream, both reading its properties and binary data. When called, "BI" has already been read from the stream. This function finishes reading through "EI" and then returns the ContentStreamInlineImage.

type ContentStreamProcessor

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

ContentStreamProcessor defines a data structure and methods for processing a content stream, keeping track of the current graphics state, and allowing external handlers to define their own functions as a part of the processing, for example rendering or extracting certain information.

func NewContentStreamProcessor

func NewContentStreamProcessor(ops []*ContentStreamOperation) *ContentStreamProcessor

NewContentStreamProcessor returns a new ContentStreamProcessor for operations `ops`.

func (*ContentStreamProcessor) AddHandler

func (proc *ContentStreamProcessor) AddHandler(condition HandlerConditionEnum, operand string, handler HandlerFunc)

AddHandler adds a new ContentStreamProcessor `handler` of type `condition` for `operand`.

func (*ContentStreamProcessor) Process

func (proc *ContentStreamProcessor) Process(resources *model.PdfPageResources) error

Process processes the entire list of operations. Maintains the graphics state that is passed to any handlers that are triggered during processing (either on specific operators or all).

type GraphicStateStack

type GraphicStateStack []GraphicsState

GraphicStateStack represents a stack of GraphicsState.

func (*GraphicStateStack) Pop

func (gsStack *GraphicStateStack) Pop() GraphicsState

Pop pops and returns the topmost GraphicsState off the `gsStack`.

func (*GraphicStateStack) Push

func (gsStack *GraphicStateStack) Push(gs GraphicsState)

Push pushes `gs` on the `gsStack`.

type GraphicsState

type GraphicsState struct {
	ColorspaceStroking    model.PdfColorspace
	ColorspaceNonStroking model.PdfColorspace
	ColorStroking         model.PdfColor
	ColorNonStroking      model.PdfColor
	CTM                   transform.Matrix
}

GraphicsState is a basic graphics state implementation for PDF processing. Initially only implementing and tracking a portion of the information specified. Easy to add more.

func (*GraphicsState) Transform

func (gs *GraphicsState) Transform(x, y float64) (float64, float64)

Transform returns coordinates x, y transformed by the CTM.

type HandlerConditionEnum

type HandlerConditionEnum int

HandlerConditionEnum represents the type of operand content stream processor (handler). The handler may process a single specific named operand or all operands.

const (
	HandlerConditionEnumOperand     HandlerConditionEnum = iota // Single (specific) operand.
	HandlerConditionEnumAllOperands                             // All operands.
)

Handler types.

func (HandlerConditionEnum) All

func (hce HandlerConditionEnum) All() bool

All returns true if `hce` is equivalent to HandlerConditionEnumAllOperands.

func (HandlerConditionEnum) Operand

func (hce HandlerConditionEnum) Operand() bool

Operand returns true if `hce` is equivalent to HandlerConditionEnumOperand.

type HandlerFunc

type HandlerFunc func(op *ContentStreamOperation, gs GraphicsState, resources *model.PdfPageResources) error

HandlerFunc is the function syntax that the ContentStreamProcessor handler must implement.

Directories

Path Synopsis
Package draw has handy features for defining paths which can be used to draw content on a PDF page.
Package draw has handy features for defining paths which can be used to draw content on a PDF page.

Jump to

Keyboard shortcuts

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