unidoc: github.com/unidoc/unidoc/pdf/contentstream Index | Files | Directories

package contentstream

import "github.com/unidoc/unidoc/pdf/contentstream"

The contentstream package 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

Package Files

const.go contentstream.go creator.go doc.go encoding.go inline-image.go parser.go processor.go utils.go

Variables

var (
    ErrInvalidOperand = errors.New("invalid operand")
)

type ContentCreator Uses

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

func NewContentCreator Uses

func NewContentCreator() *ContentCreator

func (*ContentCreator) Add_B Uses

func (this *ContentCreator) Add_B() *ContentCreator

B: Fill and then stroke the path (nonzero winding number rule).

func (*ContentCreator) Add_BT Uses

func (this *ContentCreator) Add_BT() *ContentCreator

BT: Begin text.

func (*ContentCreator) Add_B_starred Uses

func (this *ContentCreator) Add_B_starred() *ContentCreator

B*: Fill and then stroke the path (even-odd rule).

func (*ContentCreator) Add_CS Uses

func (this *ContentCreator) Add_CS(name PdfObjectName) *ContentCreator

CS: Set the current colorspace for stroking operations.

func (*ContentCreator) Add_Do Uses

func (this *ContentCreator) Add_Do(name PdfObjectName) *ContentCreator

Display XObject - image or form.

func (*ContentCreator) Add_ET Uses

func (this *ContentCreator) Add_ET() *ContentCreator

ET: End text.

func (*ContentCreator) Add_G Uses

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

G: Set the stroking colorspace to DeviceGray and sets the gray level (0-1).

func (*ContentCreator) Add_J Uses

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

Set the line cap style.

func (*ContentCreator) Add_K Uses

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

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

func (*ContentCreator) Add_M Uses

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

Set the miter limit.

func (*ContentCreator) Add_Q Uses

func (this *ContentCreator) Add_Q() *ContentCreator

Restore the most recently stored state from the stack - pop.

func (*ContentCreator) Add_RG Uses

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

RG: Set the stroking colorspace to DeviceRGB and sets the r,g,b colors (0-1 each).

func (*ContentCreator) Add_S Uses

func (this *ContentCreator) Add_S() *ContentCreator

S: stroke the path.

func (*ContentCreator) Add_SC Uses

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

SC: Set color for stroking operations. Input: c1, ..., cn.

func (*ContentCreator) Add_SCN Uses

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

SCN: Same as SC but supports more colorspaces.

func (*ContentCreator) Add_SCN_pattern Uses

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

SCN with name attribute (for pattern). Syntax: c1 ... cn name SCN.

func (*ContentCreator) Add_TD Uses

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

TD: Move to start of next line with offset (tx, ty).

func (*ContentCreator) Add_TJ Uses

func (this *ContentCreator) Add_TJ(vals ...PdfObject) *ContentCreator

TJ. Show one or more text string. Array of numbers (displacement) and strings.

func (*ContentCreator) Add_TL Uses

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

TL: Set leading.

func (*ContentCreator) Add_Tc Uses

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

Tc: Set character spacing.

func (*ContentCreator) Add_Td Uses

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

Td: Move to start of next line with offset (tx, ty).

func (*ContentCreator) Add_Tf Uses

func (this *ContentCreator) Add_Tf(fontName PdfObjectName, fontSize float64) *ContentCreator

Tf: Set font and font size.

func (*ContentCreator) Add_Tj Uses

func (this *ContentCreator) Add_Tj(textstr PdfObjectString) *ContentCreator

Tj: Show a text string.

func (*ContentCreator) Add_Tm Uses

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

Tm: Set the text line matrix.

func (*ContentCreator) Add_Tr Uses

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

Tr: Set text rendering mode.

func (*ContentCreator) Add_Ts Uses

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

Ts: Set text rise.

func (*ContentCreator) Add_Tstar Uses

func (this *ContentCreator) Add_Tstar() *ContentCreator

T*: Move to the start of next line.

func (*ContentCreator) Add_Tw Uses

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

Tw: Set word spacing.

func (*ContentCreator) Add_Tz Uses

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

Tz: Set horizontal scaling.

func (*ContentCreator) Add_W Uses

func (this *ContentCreator) Add_W() *ContentCreator

W: Modify the current clipping path by intersecting with the current path (nonzero winding rule).

func (*ContentCreator) Add_W_starred Uses

func (this *ContentCreator) Add_W_starred() *ContentCreator

W*: Modify the current clipping path by intersecting with the current path (even odd rule).

func (*ContentCreator) Add_b Uses

func (this *ContentCreator) Add_b() *ContentCreator

b: Close, fill and then stroke the path (nonzero winding number rule).

func (*ContentCreator) Add_b_starred Uses

func (this *ContentCreator) Add_b_starred() *ContentCreator

b*: Close, fill and then stroke the path (even-odd winding number rule).

func (*ContentCreator) Add_c Uses

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

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

func (*ContentCreator) Add_cm Uses

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

Modify the current transformation matrix (ctm).

func (*ContentCreator) Add_cs Uses

func (this *ContentCreator) Add_cs(name PdfObjectName) *ContentCreator

cs: Same as CS but for non-stroking operations.

func (*ContentCreator) Add_d Uses

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

Set the line dash pattern.

func (*ContentCreator) Add_f Uses

func (this *ContentCreator) Add_f() *ContentCreator

f: Fill the path using the nonzero winding number rule to determine fill region.

func (*ContentCreator) Add_f_starred Uses

func (this *ContentCreator) Add_f_starred() *ContentCreator

f*: Fill the path using the even-odd rule to determine fill region.

func (*ContentCreator) Add_g Uses

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

g: Same as G but used for nonstroking operations.

func (*ContentCreator) Add_gs Uses

func (this *ContentCreator) Add_gs(dictName PdfObjectName) *ContentCreator

Set the graphics state.

func (*ContentCreator) Add_h Uses

func (this *ContentCreator) Add_h() *ContentCreator

h: Close the current subpath by adding a line between the current position and the starting position.

func (*ContentCreator) Add_i Uses

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

Set the flatness tolerance.

func (*ContentCreator) Add_j Uses

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

Set the line join style.

func (*ContentCreator) Add_k Uses

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

k: Same as K but used for nonstroking operations.

func (*ContentCreator) Add_l Uses

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

l: Append a straight line segment from the current point to (x,y).

func (*ContentCreator) Add_m Uses

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

m: Move the current point to (x,y).

func (*ContentCreator) Add_n Uses

func (this *ContentCreator) Add_n() *ContentCreator

n: End the path without filling or stroking.

func (*ContentCreator) Add_q Uses

func (this *ContentCreator) Add_q() *ContentCreator

Save the current graphics state on the stack - push.

func (*ContentCreator) Add_quote Uses

func (this *ContentCreator) Add_quote(textstr PdfObjectString) *ContentCreator

': Move to next line and show a string.

func (*ContentCreator) Add_quotes Uses

func (this *ContentCreator) Add_quotes(textstr PdfObjectString, aw, ac float64) *ContentCreator

”: Move to next line and show a string, using aw and ac as word and character spacing respectively.

func (*ContentCreator) Add_re Uses

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

re: Append a rectangle to the current path as a complete subpath, with lower left corner (x,y).

func (*ContentCreator) Add_rg Uses

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

rg: Same as RG but used for nonstroking operations.

func (*ContentCreator) Add_ri Uses

func (this *ContentCreator) Add_ri(intent PdfObjectName) *ContentCreator

Set the color rendering intent.

func (*ContentCreator) Add_s Uses

func (this *ContentCreator) Add_s() *ContentCreator

s: Close and stroke the path.

func (*ContentCreator) Add_scn Uses

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

scn: Same as SC but for nonstroking operations.

func (*ContentCreator) Add_scn_pattern Uses

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

scn with name attribute (for pattern). Syntax: c1 ... cn name scn.

func (*ContentCreator) Add_sh Uses

func (this *ContentCreator) Add_sh(name PdfObjectName) *ContentCreator

func (*ContentCreator) Add_v Uses

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

v: 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.

func (*ContentCreator) Add_w Uses

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

Set the line width.

func (*ContentCreator) Add_y Uses

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

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

func (*ContentCreator) Bytes Uses

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

Convert 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 (*ContentCreator) Operations Uses

func (this *ContentCreator) Operations() *ContentStreamOperations

Get the list of operations.

func (*ContentCreator) RotateDeg Uses

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

Convenience function for generating a cm command to rotate transformation matrix.

func (*ContentCreator) Scale Uses

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

Convenience function for generating a cm command to scale the transformation matrix.

func (*ContentCreator) String Uses

func (this *ContentCreator) String() string

Same as Bytes() except returns as a string for convenience.

func (*ContentCreator) Translate Uses

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

Convenience function for generating a cm operation to translate the transformation matrix.

type ContentStreamInlineImage Uses

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
}

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 Uses

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

Make a new content stream inline image object from an image.

func (*ContentStreamInlineImage) DefaultWriteString Uses

func (this *ContentStreamInlineImage) DefaultWriteString() string

func (*ContentStreamInlineImage) GetColorSpace Uses

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

func (*ContentStreamInlineImage) GetEncoder Uses

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

func (*ContentStreamInlineImage) IsMask Uses

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

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 Uses

func (this *ContentStreamInlineImage) String() string

func (*ContentStreamInlineImage) ToImage Uses

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

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

type ContentStreamOperation Uses

type ContentStreamOperation struct {
    Params  []PdfObject
    Operand string
}

type ContentStreamOperations Uses

type ContentStreamOperations []*ContentStreamOperation

func (*ContentStreamOperations) Bytes Uses

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

Convert 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) WrapIfNeeded Uses

func (this *ContentStreamOperations) WrapIfNeeded() *ContentStreamOperations

Wrap 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 Uses

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

Content stream parser.

func NewContentStreamParser Uses

func NewContentStreamParser(contentStr string) *ContentStreamParser

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

func (*ContentStreamParser) ExtractText Uses

func (this *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 Uses

func (this *ContentStreamParser) Parse() (*ContentStreamOperations, error)

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

func (*ContentStreamParser) ParseInlineImage Uses

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

Parse an inline image from a content stream, both read 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 Uses

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 Uses

func NewContentStreamProcessor(ops []*ContentStreamOperation) *ContentStreamProcessor

func (*ContentStreamProcessor) AddHandler Uses

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

func (*ContentStreamProcessor) Process Uses

func (this *ContentStreamProcessor) Process(resources *PdfPageResources) error

Process the entire operations.

type GraphicStateStack Uses

type GraphicStateStack []GraphicsState

func (*GraphicStateStack) Pop Uses

func (gsStack *GraphicStateStack) Pop() GraphicsState

func (*GraphicStateStack) Push Uses

func (gsStack *GraphicStateStack) Push(gs GraphicsState)

type GraphicsState Uses

type GraphicsState struct {
    ColorspaceStroking    PdfColorspace
    ColorspaceNonStroking PdfColorspace
    ColorStroking         PdfColor
    ColorNonStroking      PdfColor
}

Basic graphics state implementation. Initially only implementing and tracking a portion of the information specified. Easy to add more.

type HandlerConditionEnum Uses

type HandlerConditionEnum int
const (
    HandlerConditionEnumOperand     HandlerConditionEnum = iota
    HandlerConditionEnumAllOperands HandlerConditionEnum = iota
)

func (HandlerConditionEnum) All Uses

func (this HandlerConditionEnum) All() bool

func (HandlerConditionEnum) Operand Uses

func (this HandlerConditionEnum) Operand() bool

type HandlerEntry Uses

type HandlerEntry struct {
    Condition HandlerConditionEnum
    Operand   string
    Handler   HandlerFunc
}

type HandlerFunc Uses

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

Directories

PathSynopsis
drawThe draw package has handy features for defining paths which can be used to draw content on a PDF page.

Package contentstream imports 13 packages (graph) and is imported by 8 packages. Updated 2018-11-20. Refresh now. Tools for package owners.