Documentation ¶
Overview ¶
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 ¶
- type ContentCreator
- func (this *ContentCreator) Add_B() *ContentCreator
- func (this *ContentCreator) Add_BT() *ContentCreator
- func (this *ContentCreator) Add_B_starred() *ContentCreator
- func (this *ContentCreator) Add_CS(name PdfObjectName) *ContentCreator
- func (this *ContentCreator) Add_Do(name PdfObjectName) *ContentCreator
- func (this *ContentCreator) Add_ET() *ContentCreator
- func (this *ContentCreator) Add_G(gray float64) *ContentCreator
- func (this *ContentCreator) Add_J(lineCapStyle string) *ContentCreator
- func (this *ContentCreator) Add_K(c, m, y, k float64) *ContentCreator
- func (this *ContentCreator) Add_M(miterlimit float64) *ContentCreator
- func (this *ContentCreator) Add_Q() *ContentCreator
- func (this *ContentCreator) Add_RG(r, g, b float64) *ContentCreator
- func (this *ContentCreator) Add_S() *ContentCreator
- func (this *ContentCreator) Add_SC(c ...float64) *ContentCreator
- func (this *ContentCreator) Add_SCN(c ...float64) *ContentCreator
- func (this *ContentCreator) Add_SCN_pattern(name PdfObjectName, c ...float64) *ContentCreator
- func (this *ContentCreator) Add_TD(tx, ty float64) *ContentCreator
- func (this *ContentCreator) Add_TJ(vals ...PdfObject) *ContentCreator
- func (this *ContentCreator) Add_TL(leading float64) *ContentCreator
- func (this *ContentCreator) Add_Tc(charSpace float64) *ContentCreator
- func (this *ContentCreator) Add_Td(tx, ty float64) *ContentCreator
- func (this *ContentCreator) Add_Tf(fontName PdfObjectName, fontSize float64) *ContentCreator
- func (this *ContentCreator) Add_Tj(textstr PdfObjectString) *ContentCreator
- func (this *ContentCreator) Add_Tm(a, b, c, d, e, f float64) *ContentCreator
- func (this *ContentCreator) Add_Tr(render int64) *ContentCreator
- func (this *ContentCreator) Add_Ts(rise float64) *ContentCreator
- func (this *ContentCreator) Add_Tstar() *ContentCreator
- func (this *ContentCreator) Add_Tw(wordSpace float64) *ContentCreator
- func (this *ContentCreator) Add_Tz(scale float64) *ContentCreator
- func (this *ContentCreator) Add_W() *ContentCreator
- func (this *ContentCreator) Add_W_starred() *ContentCreator
- func (this *ContentCreator) Add_b() *ContentCreator
- func (this *ContentCreator) Add_b_starred() *ContentCreator
- func (this *ContentCreator) Add_c(x1, y1, x2, y2, x3, y3 float64) *ContentCreator
- func (this *ContentCreator) Add_cm(a, b, c, d, e, f float64) *ContentCreator
- func (this *ContentCreator) Add_cs(name PdfObjectName) *ContentCreator
- func (this *ContentCreator) Add_d(dashArray []int64, dashPhase int64) *ContentCreator
- func (this *ContentCreator) Add_f() *ContentCreator
- func (this *ContentCreator) Add_f_starred() *ContentCreator
- func (this *ContentCreator) Add_g(gray float64) *ContentCreator
- func (this *ContentCreator) Add_gs(dictName PdfObjectName) *ContentCreator
- func (this *ContentCreator) Add_h() *ContentCreator
- func (this *ContentCreator) Add_i(flatness float64) *ContentCreator
- func (this *ContentCreator) Add_j(lineJoinStyle string) *ContentCreator
- func (this *ContentCreator) Add_k(c, m, y, k float64) *ContentCreator
- func (this *ContentCreator) Add_l(x, y float64) *ContentCreator
- func (this *ContentCreator) Add_m(x, y float64) *ContentCreator
- func (this *ContentCreator) Add_n() *ContentCreator
- func (this *ContentCreator) Add_q() *ContentCreator
- func (this *ContentCreator) Add_quote(textstr PdfObjectString) *ContentCreator
- func (this *ContentCreator) Add_quotes(textstr PdfObjectString, aw, ac float64) *ContentCreator
- func (this *ContentCreator) Add_re(x, y, width, height float64) *ContentCreator
- func (this *ContentCreator) Add_rg(r, g, b float64) *ContentCreator
- func (this *ContentCreator) Add_ri(intent PdfObjectName) *ContentCreator
- func (this *ContentCreator) Add_s() *ContentCreator
- func (this *ContentCreator) Add_scn(c ...float64) *ContentCreator
- func (this *ContentCreator) Add_scn_pattern(name PdfObjectName, c ...float64) *ContentCreator
- func (this *ContentCreator) Add_sh(name PdfObjectName) *ContentCreator
- func (this *ContentCreator) Add_v(x2, y2, x3, y3 float64) *ContentCreator
- func (this *ContentCreator) Add_w(lineWidth float64) *ContentCreator
- func (this *ContentCreator) Add_y(x1, y1, x3, y3 float64) *ContentCreator
- func (this *ContentCreator) Bytes() []byte
- func (this *ContentCreator) Operations() *ContentStreamOperations
- func (this *ContentCreator) RotateDeg(angle float64) *ContentCreator
- func (this *ContentCreator) Scale(sx, sy float64) *ContentCreator
- func (this *ContentCreator) String() string
- func (this *ContentCreator) Translate(tx, ty float64) *ContentCreator
- type ContentStreamInlineImage
- func (this *ContentStreamInlineImage) DefaultWriteString() string
- func (this *ContentStreamInlineImage) GetColorSpace(resources *model.PdfPageResources) (model.PdfColorspace, error)
- func (this *ContentStreamInlineImage) GetEncoder() (core.StreamEncoder, error)
- func (this *ContentStreamInlineImage) IsMask() (bool, error)
- func (this *ContentStreamInlineImage) String() string
- func (this *ContentStreamInlineImage) ToImage(resources *model.PdfPageResources) (*model.Image, error)
- type ContentStreamOperation
- type ContentStreamOperations
- type ContentStreamParser
- type ContentStreamProcessor
- type GraphicStateStack
- type GraphicsState
- type HandlerConditionEnum
- type HandlerEntry
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentCreator ¶
type ContentCreator struct {
// contains filtered or unexported fields
}
func NewContentCreator ¶
func NewContentCreator() *ContentCreator
func (*ContentCreator) Add_B ¶
func (this *ContentCreator) Add_B() *ContentCreator
B: Fill and then stroke the path (nonzero winding number rule).
func (*ContentCreator) Add_BT ¶
func (this *ContentCreator) Add_BT() *ContentCreator
BT: Begin text.
func (*ContentCreator) Add_B_starred ¶
func (this *ContentCreator) Add_B_starred() *ContentCreator
B*: Fill and then stroke the path (even-odd rule).
func (*ContentCreator) Add_CS ¶
func (this *ContentCreator) Add_CS(name PdfObjectName) *ContentCreator
CS: Set the current colorspace for stroking operations.
func (*ContentCreator) Add_Do ¶
func (this *ContentCreator) Add_Do(name PdfObjectName) *ContentCreator
Display XObject - image or form.
func (*ContentCreator) Add_G ¶
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 ¶
func (this *ContentCreator) Add_J(lineCapStyle string) *ContentCreator
Set the line cap style.
func (*ContentCreator) Add_K ¶
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 ¶
func (this *ContentCreator) Add_M(miterlimit float64) *ContentCreator
Set the miter limit.
func (*ContentCreator) Add_Q ¶
func (this *ContentCreator) Add_Q() *ContentCreator
Restore the most recently stored state from the stack - pop.
func (*ContentCreator) Add_RG ¶
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 ¶
func (this *ContentCreator) Add_S() *ContentCreator
S: stroke the path.
func (*ContentCreator) Add_SC ¶
func (this *ContentCreator) Add_SC(c ...float64) *ContentCreator
SC: Set color for stroking operations. Input: c1, ..., cn.
func (*ContentCreator) Add_SCN ¶
func (this *ContentCreator) Add_SCN(c ...float64) *ContentCreator
SCN: Same as SC but supports more colorspaces.
func (*ContentCreator) Add_SCN_pattern ¶
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 ¶
func (this *ContentCreator) Add_TD(tx, ty float64) *ContentCreator
TD: Move to start of next line with offset (tx, ty).
func (*ContentCreator) Add_TJ ¶
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 ¶
func (this *ContentCreator) Add_TL(leading float64) *ContentCreator
TL: Set leading.
func (*ContentCreator) Add_Tc ¶
func (this *ContentCreator) Add_Tc(charSpace float64) *ContentCreator
Tc: Set character spacing.
func (*ContentCreator) Add_Td ¶
func (this *ContentCreator) Add_Td(tx, ty float64) *ContentCreator
Td: Move to start of next line with offset (tx, ty).
func (*ContentCreator) Add_Tf ¶
func (this *ContentCreator) Add_Tf(fontName PdfObjectName, fontSize float64) *ContentCreator
Tf: Set font and font size.
func (*ContentCreator) Add_Tj ¶
func (this *ContentCreator) Add_Tj(textstr PdfObjectString) *ContentCreator
Tj: Show a text string.
func (*ContentCreator) Add_Tm ¶
func (this *ContentCreator) Add_Tm(a, b, c, d, e, f float64) *ContentCreator
Tm: Set the text line matrix.
func (*ContentCreator) Add_Tr ¶
func (this *ContentCreator) Add_Tr(render int64) *ContentCreator
Tr: Set text rendering mode.
func (*ContentCreator) Add_Ts ¶
func (this *ContentCreator) Add_Ts(rise float64) *ContentCreator
Ts: Set text rise.
func (*ContentCreator) Add_Tstar ¶
func (this *ContentCreator) Add_Tstar() *ContentCreator
T*: Move to the start of next line.
func (*ContentCreator) Add_Tw ¶
func (this *ContentCreator) Add_Tw(wordSpace float64) *ContentCreator
Tw: Set word spacing.
func (*ContentCreator) Add_Tz ¶
func (this *ContentCreator) Add_Tz(scale float64) *ContentCreator
Tz: Set horizontal scaling.
func (*ContentCreator) Add_W ¶
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 ¶
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 ¶
func (this *ContentCreator) Add_b() *ContentCreator
b: Close, fill and then stroke the path (nonzero winding number rule).
func (*ContentCreator) Add_b_starred ¶
func (this *ContentCreator) Add_b_starred() *ContentCreator
b*: Close, fill and then stroke the path (even-odd winding number rule).
func (*ContentCreator) Add_c ¶
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 ¶
func (this *ContentCreator) Add_cm(a, b, c, d, e, f float64) *ContentCreator
Modify the current transformation matrix (ctm).
func (*ContentCreator) Add_cs ¶
func (this *ContentCreator) Add_cs(name PdfObjectName) *ContentCreator
cs: Same as CS but for non-stroking operations.
func (*ContentCreator) Add_d ¶
func (this *ContentCreator) Add_d(dashArray []int64, dashPhase int64) *ContentCreator
Set the line dash pattern.
func (*ContentCreator) Add_f ¶
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 ¶
func (this *ContentCreator) Add_f_starred() *ContentCreator
f*: Fill the path using the even-odd rule to determine fill region.
func (*ContentCreator) Add_g ¶
func (this *ContentCreator) Add_g(gray float64) *ContentCreator
g: Same as G but used for nonstroking operations.
func (*ContentCreator) Add_gs ¶
func (this *ContentCreator) Add_gs(dictName PdfObjectName) *ContentCreator
Set the graphics state.
func (*ContentCreator) Add_h ¶
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 ¶
func (this *ContentCreator) Add_i(flatness float64) *ContentCreator
Set the flatness tolerance.
func (*ContentCreator) Add_j ¶
func (this *ContentCreator) Add_j(lineJoinStyle string) *ContentCreator
Set the line join style.
func (*ContentCreator) Add_k ¶
func (this *ContentCreator) Add_k(c, m, y, k float64) *ContentCreator
k: Same as K but used for nonstroking operations.
func (*ContentCreator) Add_l ¶
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 ¶
func (this *ContentCreator) Add_m(x, y float64) *ContentCreator
m: Move the current point to (x,y).
func (*ContentCreator) Add_n ¶
func (this *ContentCreator) Add_n() *ContentCreator
n: End the path without filling or stroking.
func (*ContentCreator) Add_q ¶
func (this *ContentCreator) Add_q() *ContentCreator
Save the current graphics state on the stack - push.
func (*ContentCreator) Add_quote ¶
func (this *ContentCreator) Add_quote(textstr PdfObjectString) *ContentCreator
': Move to next line and show a string.
func (*ContentCreator) Add_quotes ¶
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 ¶
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 ¶
func (this *ContentCreator) Add_rg(r, g, b float64) *ContentCreator
rg: Same as RG but used for nonstroking operations.
func (*ContentCreator) Add_ri ¶
func (this *ContentCreator) Add_ri(intent PdfObjectName) *ContentCreator
Set the color rendering intent.
func (*ContentCreator) Add_s ¶
func (this *ContentCreator) Add_s() *ContentCreator
s: Close and stroke the path.
func (*ContentCreator) Add_scn ¶
func (this *ContentCreator) Add_scn(c ...float64) *ContentCreator
scn: Same as SC but for nonstroking operations.
func (*ContentCreator) Add_scn_pattern ¶
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 ¶
func (this *ContentCreator) Add_sh(name PdfObjectName) *ContentCreator
func (*ContentCreator) Add_v ¶
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 ¶
func (this *ContentCreator) Add_w(lineWidth float64) *ContentCreator
Set the line width.
func (*ContentCreator) Add_y ¶
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 ¶
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 ¶
func (this *ContentCreator) Operations() *ContentStreamOperations
Get the list of operations.
func (*ContentCreator) RotateDeg ¶
func (this *ContentCreator) RotateDeg(angle float64) *ContentCreator
Convenience function for generating a cm command to rotate transformation matrix.
func (*ContentCreator) Scale ¶
func (this *ContentCreator) Scale(sx, sy float64) *ContentCreator
Convenience function for generating a cm command to scale the transformation matrix.
func (*ContentCreator) String ¶
func (this *ContentCreator) String() string
Same as Bytes() except returns as a string for convenience.
func (*ContentCreator) Translate ¶
func (this *ContentCreator) Translate(tx, ty float64) *ContentCreator
Convenience function for generating a cm operation to translate the transformation matrix.
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 }
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)
Make a new content stream inline image object from an image.
func (*ContentStreamInlineImage) DefaultWriteString ¶
func (this *ContentStreamInlineImage) DefaultWriteString() string
func (*ContentStreamInlineImage) GetColorSpace ¶
func (this *ContentStreamInlineImage) GetColorSpace(resources *model.PdfPageResources) (model.PdfColorspace, error)
func (*ContentStreamInlineImage) GetEncoder ¶
func (this *ContentStreamInlineImage) GetEncoder() (core.StreamEncoder, error)
func (*ContentStreamInlineImage) IsMask ¶
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 ¶
func (this *ContentStreamInlineImage) String() string
func (*ContentStreamInlineImage) ToImage ¶
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 ¶
type ContentStreamOperation struct { Params []PdfObject Operand string }
type ContentStreamOperations ¶
type ContentStreamOperations []*ContentStreamOperation
func (*ContentStreamOperations) Bytes ¶
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 ¶
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 ¶
type ContentStreamParser struct {
// contains filtered or unexported fields
}
Content stream parser.
func NewContentStreamParser ¶
func NewContentStreamParser(contentStr string) *ContentStreamParser
Create a new instance of the content stream parser from an input content stream string.
func (*ContentStreamParser) ExtractText
deprecated
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 ¶
func (this *ContentStreamParser) Parse() (*ContentStreamOperations, error)
Parses all commands in content stream, returning a list of operation data.
func (*ContentStreamParser) ParseInlineImage ¶
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 ¶
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
func (*ContentStreamProcessor) AddHandler ¶
func (csp *ContentStreamProcessor) AddHandler(condition HandlerConditionEnum, operand string, handler HandlerFunc)
func (*ContentStreamProcessor) Process ¶
func (this *ContentStreamProcessor) Process(resources *PdfPageResources) error
Process the entire operations.
type GraphicStateStack ¶
type GraphicStateStack []GraphicsState
func (*GraphicStateStack) Pop ¶
func (gsStack *GraphicStateStack) Pop() GraphicsState
func (*GraphicStateStack) Push ¶
func (gsStack *GraphicStateStack) Push(gs GraphicsState)
type GraphicsState ¶
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 ¶
type HandlerConditionEnum int
const ( HandlerConditionEnumOperand HandlerConditionEnum = iota HandlerConditionEnumAllOperands HandlerConditionEnum = iota )
func (HandlerConditionEnum) All ¶
func (this HandlerConditionEnum) All() bool
func (HandlerConditionEnum) Operand ¶
func (this HandlerConditionEnum) Operand() bool
type HandlerEntry ¶
type HandlerEntry struct { Condition HandlerConditionEnum Operand string Handler HandlerFunc }
type HandlerFunc ¶
type HandlerFunc func(op *ContentStreamOperation, gs GraphicsState, resources *PdfPageResources) error