Documentation ¶
Index ¶
- Constants
- Variables
- func FUToPt(n, fontSize float64) float64
- func PtToFU(n, fontSize float64) float64
- func TransformRect(r Rect, m Matrix) (LL Point, UL Point, LR Point, UR Point)
- type AcroField
- type AcroTextCfg
- type BlendMode
- type CMYKColor
- type CheckboxCfg
- type Color
- type ColorSpace
- type ContentStream
- func (c *ContentStream) Arc(cx, cy, rx, ry, theta, delta float64)
- func (c *ContentStream) Arc2(cx, cy, rx, ry, theta, delta, phi, step float64)
- func (c *ContentStream) BeginText() (EndText, error)
- func (c *ContentStream) Circle(cx, cy, r float64)
- func (c *ContentStream) Clip(wr FillRule)
- func (c *ContentStream) ClosePath()
- func (c *ContentStream) ClosePathFillStroke(fr FillRule)
- func (c *ContentStream) ClosePathStroke()
- func (c *ContentStream) Concat(m Matrix)
- func (c *ContentStream) CubicBezier1(x1, y1, x2, y2, x3, y3 float64)
- func (c *ContentStream) CubicBezier2(x2, y2, x3, y3 float64)
- func (c *ContentStream) CubicBezier3(x1, y1, x3, y3 float64)
- func (c *ContentStream) DrawImage(img *Image)
- func (c *ContentStream) DrawImageTo(dst Rect, x *Image)
- func (c *ContentStream) DrawLine(x1, y1, x2, y2 float64)
- func (c *ContentStream) DrawXContent(x *XContent)
- func (c *ContentStream) DrawXContentTo(dst Rect, x *XContent)
- func (c *ContentStream) Ellipse(cx, cy, rx, ry float64)
- func (c *ContentStream) EndPath()
- func (c *ContentStream) Extent(t []rune) float64
- func (c *ContentStream) ExtentKerns(t []rune, kerns []int) (float64, error)
- func (c *ContentStream) Fill(fr FillRule)
- func (c *ContentStream) FillStroke(fr FillRule)
- func (c *ContentStream) LineString(s string)
- func (c *ContentStream) LineTo(x, y float64)
- func (c *ContentStream) MoveTo(x, y float64)
- func (c *ContentStream) NextLine()
- func (c *ContentStream) QRestore() error
- func (c *ContentStream) QSave()
- func (c *ContentStream) RawExtent(t []rune) float64
- func (c *ContentStream) RawTextCursor() Point
- func (c *ContentStream) Re(x, y, w, h float64)
- func (c *ContentStream) Re2(r Rect)
- func (c *ContentStream) SVGArc(s SVGArcParams, h float64, m Matrix)
- func (c *ContentStream) SetAlphaConst(a float64, stroke bool)
- func (c *ContentStream) SetCharSpace(f float64)
- func (c *ContentStream) SetColor(cl Color)
- func (c *ContentStream) SetColorStroke(cl Color)
- func (c *ContentStream) SetDashPattern(d DashPattern)
- func (c *ContentStream) SetExtGS(extGState map[string]any)
- func (c *ContentStream) SetFlatness(f float64)
- func (c *ContentStream) SetFont(size float64, font *Font)
- func (c *ContentStream) SetHScale(f float64)
- func (c *ContentStream) SetLeading(f float64)
- func (c *ContentStream) SetLineCap(lc LineCap)
- func (c *ContentStream) SetLineJoin(lj LineJoin)
- func (c *ContentStream) SetLineWidth(f float64)
- func (c *ContentStream) SetMiterLimit(ml float64)
- func (c *ContentStream) SetRenderIntent(n string)
- func (c *ContentStream) SetRenderMode(r RenderMode)
- func (c *ContentStream) SetRise(f float64)
- func (c *ContentStream) SetTextMatrix(m Matrix)
- func (c *ContentStream) SetTextOffset(x, y float64)
- func (c *ContentStream) SetTextOffsetLeading(x, y float64)
- func (c *ContentStream) SetWordSpace(f float64)
- func (c *ContentStream) ShowString(s string)
- func (c *ContentStream) ShowText(t []rune, kerns []int) error
- func (c *ContentStream) Stroke()
- func (c *ContentStream) TextCursor() Point
- type DashPattern
- type DefaultSubsetter
- type EndText
- type FillRule
- type Filter
- type Font
- type FontFlag
- type FontSubsetter
- type GColor
- type GS
- type Image
- type InfoDict
- type LineCap
- type LineJoin
- type Margins
- type Matrix
- type PDF
- func (p *PDF) AddXMPMetaData(b []byte)
- func (p *PDF) AppendPage(page *Page)
- func (p *PDF) InsertPage(page *Page, i int) error
- func (p *PDF) NewAcroField() *AcroField
- func (p *PDF) NewImage(x XImage) *Image
- func (p *PDF) ReplacePage(page *Page, i int) error
- func (p *PDF) SetInfo(id InfoDict)
- func (p *PDF) SetLanguage(s string)
- func (p *PDF) SetViewPrefs(v ViewPrefs)
- func (p *PDF) WriteTo(w io.Writer) (int64, error)
- type Page
- type PageRange
- type PathState
- type Point
- type RGBColor
- type Rect
- type RenderMode
- type SVGArcParams
- type TextAnnot
- type TextObj
- type TextState
- type ViewPrefs
- type Widget
- type WidgetCfger
- type XContent
- type XImage
Constants ¶
const ( AcroButton acroType = iota // Form type that includes checkboxes. AcroText )
const ( DefaultFieldFlags fieldFlags = 0 // fieldFlags common to all AcroField types (Table 227) FfReadOnly fieldFlags = 1 FfRequired fieldFlags = 1 << 1 FfNoExport fieldFlags = 1 << 2 // fieldFlags specific to button-type AcroFields (Table 229) FfNoToggleToOff fieldFlags = 1 << 14 FfRadio fieldFlags = 1 << 15 FfRadiosInUnison fieldFlags = 1 << 25 // fieldFlags specific to text-type AcroFields (Table 231) FfMultiline fieldFlags = 1 << 12 FfPassword fieldFlags = 1 << 13 FfFileSelect fieldFlags = 1 << 20 FfDoNotSpellCheck fieldFlags = 1 << 22 // can also be used with choice-type AcroFields FfDoNotScroll fieldFlags = 1 << 23 FfComb fieldFlags = 1 << 24 FfRichText fieldFlags = 1 << 25 // fieldFlags specific to choice-type AcroFields (Table 233) FfCombo fieldFlags = 1 << 17 FfEdit fieldFlags = 1 << 18 FfSort fieldFlags = 1 << 19 FfMultiSelect fieldFlags = 1 << 21 FfCommitOnSelChange fieldFlags = 1 << 26 )
const ( // Flags specifying the behavior of TextAnnots and Widgets. InvisibleAnnot annotFlag = 1 << iota HiddenAnnot PrintAnnot // IMPORTANT: must be set for an annotation to appear when printed. NoZoomAnnot NoRotateAnnot NoViewAnnot ReadOnlyAnnot LockedAnnot ToggleNoViewAnnot LockedContentsAnnot )
const ( // PDF-viewer defined text annotation icon styles. CommentIcon textAnnotStyle = iota KeyIcon NoteIcon HelpIcon NewParagraphIcon ParagraphIcon InsertIcon )
const ( SinglePage pageLayout = 1 + iota OneColumn TwoColumnLeft TwoColumnRight TwoPageLeft TwoPageRight )
const ( DefaultMode pageMode = 1 + iota OutlinesMode ThumbsMode FullScreenMode OCMode AttachmentsMode )
const ( Deg float64 = math.Pi / 180 // 1 degree in radians In float64 = 72 // 1 inch in points Pica float64 = In / 6 // 1 PostScript pica in points Cm float64 = In / 2.54 // 1 centimeter in points Mm float64 = Cm / 10 // 1 millimeter in points )
const ( UseNone preference UseOutlines UseThumbs UseOC L2R R2L AppDefaultScaling NoScaling Simplex DuplexFlipShortEdge DuplexFlipLongEdge )
Variables ¶
var ( Red = RGBColor{1, 0, 0} Green = RGBColor{0, 1, 0} Blue = RGBColor{0, 0, 1} )
var ( Cyan = CMYKColor{1, 0, 0, 0} Magenta = CMYKColor{0, 1, 0, 0} Yellow = CMYKColor{0, 0, 1, 0} CMYKBlack = CMYKColor{0, 0, 0, 1} )
var ( ErrNested = fmt.Errorf("text objects cannot be statically nested") ErrClosed = fmt.Errorf("text object is already closed") )
var ( A5 = Rect{0, 0, 148 * Mm, 210 * Mm} A4 = Rect{0, 0, 210 * Mm, 297 * Mm} A3 = Rect{0, 0, 297 * Mm, 420 * Mm} USLetter = Rect{0, 0, 8.5 * In, 11 * In} USLegal = Rect{0, 0, 8.5 * In, 14 * In} USTabloid = Rect{0, 0, 11 * In, 17 * In} )
var ( NoMargins = Margins{} HalfInch = Margins{.5 * In, .5 * In, .5 * In, .5 * In} OneInch = Margins{In, In, In, In} OneCm = Margins{Cm, Cm, Cm, Cm} FivePt = Margins{5, 5, 5, 5} )
var (
ErrChildren = fmt.Errorf("acrofields supported by gdf may have at most 1 child")
)
Functions ¶
Types ¶
type AcroField ¶ added in v0.0.15
type AcroField struct { Name string // the partial field name Flags fieldFlags // field flags // contains filtered or unexported fields }
An AcroField is an interactive element within a PDF. All AcroField elements are children of a document-level acroform node. Each AcroField must be instantiated on a Page by a Widget, and can be associated with only 1 Widget.
type AcroTextCfg ¶ added in v0.0.15
type AcroTextCfg struct { Flags annotFlag Appearance *XContent Font *Font FontSize float64 IsMultiLine bool MaxLen int }
AcroTextCfgs can be used to instantiate text-type AcroFields. The PrintAnnot flag should be set in almost all cases. The Appearance *XObject can be left nil. Implements WidgetCfger.
type CMYKColor ¶
type CMYKColor struct {
C, M, Y, K float64
}
CMYK Color; C, M, Y, and K must be in [0,1].
type CheckboxCfg ¶ added in v0.0.15
CheckBoxCfgs can be used to instantiate checkbox/button-type AcroFields. The PrintAnnot flag should be set in almost all cases. The Off and On *XObjects are mandatory, but can be reused by multiple Widgets. Implements WidgetCfger.
func DefaultCheckbox ¶ added in v0.0.15
func DefaultCheckbox() CheckboxCfg
The PDF spec requires a PDF document to describe the appearance of any acroform fields it contains. This means that the appearance of each form field is customizable, but it also means that the 'On' and 'Off' states (as well as the default state) of a checkbox need to be specified in advance. DefaultCheckbox is a convenience function that returns a Checkbox design suitable for use with most sizes of Checkbox. Checkboxes with dimensions smaller than 4 pts will look bad. The returned Checkbox design can be reused for any Checkbox-type (Button) acroform fields of the same size. NOTE: The appearance of a Checkbox may be dependent on the PDF viewer used to render it. This can be especially noticeable when withBorder is true. It is often preferable to draw the Checkbox border separately.
type ColorSpace ¶
type ColorSpace uint
const ( DeviceGray ColorSpace = iota DeviceRGB DeviceCMYK PatternCS )
func (ColorSpace) String ¶ added in v0.0.15
func (c ColorSpace) String() string
type ContentStream ¶
func (*ContentStream) Arc ¶ added in v0.1.5
func (c *ContentStream) Arc(cx, cy, rx, ry, theta, delta float64)
Arc draws an elliptic arc. If e is an ellipse defined by the parametric function y(theta) = cy + ry*sin(theta) and x(theta) = cx + rx*cos(theta), then the arc is the segment of the ellipse that begins at e(theta) and ends at e(theta+delta). If delta is negative, the arc is drawn clockwise.
func (*ContentStream) Arc2 ¶ added in v0.1.5
func (c *ContentStream) Arc2(cx, cy, rx, ry, theta, delta, phi, step float64)
Arc2 draws an elliptic arc. It is similar to Arc, but includes additional parameters. phi indicates an angle relative to the x-axis that the arc is rotated about its center point. step is the maximum size in radians of each segment of the arc. This value must be greater than 0 and less than or equal to pi. Lower values increase the accuracy of the arc, but can cause significant performance degradations. In practice, values of pi/2 and pi/4 are reasonable upper- and lower-bounds. The Arc method uses pi/2 by default. Note: the step argument has no effect on arcs with deltas that have an absolute value less than the value of step.
func (*ContentStream) BeginText ¶ added in v0.0.4
func (c *ContentStream) BeginText() (EndText, error)
BeginText declares a new text object within the ContentStream. It must be called before drawing any text to c. It returns an EndText function, which must be called to close the text object, and an error. All successive calls to BeginText before EndText is called will result in an error. Pairs of BeginText/EndText calls should not be interleaved with pairs of QSave/Restore calls, although each pair can fully contain instances of the other pair. BeginText automatically sets the current Text Matrix and the Line Matrix equal to the identity matrix. If you do not wish for all glyphs to appear at the origin, you must also adjust the current Text Matrix.
func (*ContentStream) Circle ¶ added in v0.0.18
func (c *ContentStream) Circle(cx, cy, r float64)
Circle begins a new path and appends a circle of radius r with a center point of (cx, cy) to the path. The new current point becomes (cx + r, cy).
func (*ContentStream) Clip ¶ added in v0.0.5
func (c *ContentStream) Clip(wr FillRule)
Clip clips the path. It may appear after the last path construction operator and before the path-painting operator that terminates a path object.
func (*ContentStream) ClosePath ¶ added in v0.0.3
func (c *ContentStream) ClosePath()
ClosePath closes the current path; h.
func (*ContentStream) ClosePathFillStroke ¶ added in v0.0.5
func (c *ContentStream) ClosePathFillStroke(fr FillRule)
ClosePathFillStroke closes the path, fills the path, and then strokes the path; b.
func (*ContentStream) ClosePathStroke ¶ added in v0.0.5
func (c *ContentStream) ClosePathStroke()
ClosePathStroke closes and strokes the path; s.
func (*ContentStream) Concat ¶ added in v0.0.9
func (c *ContentStream) Concat(m Matrix)
Sets c's Current Transformation Matrix (c.GS.Matrix) to the matrix product of m and c.GS.Matrix.
func (*ContentStream) CubicBezier1 ¶ added in v0.0.10
func (c *ContentStream) CubicBezier1(x1, y1, x2, y2, x3, y3 float64)
CubicBezier1 appends a cubic Bézier curve to the current path; c. The curve extends from the current point to (x3, y3) using using (x1, y1) and (x2, y2) as the Bézier control points. If the PathState is not Building, no action is taken.
func (*ContentStream) CubicBezier2 ¶ added in v0.0.10
func (c *ContentStream) CubicBezier2(x2, y2, x3, y3 float64)
CubicBezier2 appends a cubic Bézier curve to the current path; v. The curve extends from the current point to (x3, y3), using the current point and (x2, y2) as the Bézier control points. If the PathState is not Building, no action is taken.
func (*ContentStream) CubicBezier3 ¶ added in v0.0.10
func (c *ContentStream) CubicBezier3(x1, y1, x3, y3 float64)
CubicBezier3 appends a cubic Bézier curve to the current path; y. The curve extends from the current point to (x3, y3), using (x1, y1) and (x3, y3) as the Bézier control points. If the PathState is not Building, no action is taken.
func (*ContentStream) DrawImage ¶ added in v0.1.0
func (c *ContentStream) DrawImage(img *Image)
func (*ContentStream) DrawImageTo ¶ added in v0.1.0
func (c *ContentStream) DrawImageTo(dst Rect, x *Image)
func (*ContentStream) DrawLine ¶ added in v0.0.15
func (c *ContentStream) DrawLine(x1, y1, x2, y2 float64)
DrawLine is a convenience function that strokes a line from Point{x1,y1} to Point{x2,y2}.
func (*ContentStream) DrawXContent ¶ added in v0.1.0
func (c *ContentStream) DrawXContent(x *XContent)
DrawXContent draws x to c at c's current point.
func (*ContentStream) DrawXContentTo ¶ added in v0.1.0
func (c *ContentStream) DrawXContentTo(dst Rect, x *XContent)
DrawXContent adjusts the CTM such that the contents of x are drawn to dst.
func (*ContentStream) Ellipse ¶ added in v0.0.18
func (c *ContentStream) Ellipse(cx, cy, rx, ry float64)
Ellipse begins a new path and appends an ellipse with a center point of (cx, cy), an x-radius of rx, and a y-radius of ry to the path.
func (*ContentStream) EndPath ¶ added in v0.0.3
func (c *ContentStream) EndPath()
EndPath ends the current path. It is used primarily to apply changes to the current clipping path; n.
func (*ContentStream) Extent ¶ added in v0.1.3
func (c *ContentStream) Extent(t []rune) float64
Extent returns the extent in font units of t, when set as a single line in c's current font. The returned value accounts for kerning, word spacing, and horizontal scaling of the text.
func (*ContentStream) ExtentKerns ¶ added in v0.1.3
func (c *ContentStream) ExtentKerns(t []rune, kerns []int) (float64, error)
ExtentKerns returns the extent in font units of t, when set as a single line and using the supplied kerning in c's current font. The returned value accounts for kerning, word spacing, and horizontal scaling of the text.
func (*ContentStream) FillStroke ¶ added in v0.0.3
func (c *ContentStream) FillStroke(fr FillRule)
FillStroke fills and then strokes the path.
func (*ContentStream) LineString ¶ added in v0.0.15
func (c *ContentStream) LineString(s string)
LineString writes s (without kerning) to c and advances the text matrix by the extent of s; '.
func (*ContentStream) LineTo ¶ added in v0.0.3
func (c *ContentStream) LineTo(x, y float64)
LineTo appends a straight line from the current point to (x, y), which becomes the new current point; l. If the PathState is not Building, no action is taken.
func (*ContentStream) MoveTo ¶ added in v0.0.3
func (c *ContentStream) MoveTo(x, y float64)
MoveTo begins a new path starting at (x, y); m.
func (*ContentStream) NextLine ¶ added in v0.0.11
func (c *ContentStream) NextLine()
NextLine begins a new text line by setting the current text matrix and line matrix equal to the line matrix offset by (0, -c.Leading); T*.
func (*ContentStream) QRestore ¶ added in v0.0.4
func (c *ContentStream) QRestore() error
QRestore pops the most recent addition to c's GSStack off the stack and sets c's current GS equal to that value. It returns an error if c's GSStack is empty or if c.BeginText() has been called after the last call to c.QSave(), and the returned EndText function has not yet been called.
func (*ContentStream) QSave ¶ added in v0.0.4
func (c *ContentStream) QSave()
QSave pushes the current GS (graphics sate) to c's GSStack (graphics state stack).
func (*ContentStream) RawExtent ¶ added in v0.1.3
func (c *ContentStream) RawExtent(t []rune) float64
RawExtent returns the extent in font units of t, when set as a single line in c's current font. The returned value accounts for word spacing and horizontal scaling of the text, but does not account for kerning.
func (*ContentStream) RawTextCursor ¶
func (c *ContentStream) RawTextCursor() Point
RawTextCursor returns the x and y coordinates of the point (0,0,1) transformed only by the current text matrix.
func (*ContentStream) Re ¶
func (c *ContentStream) Re(x, y, w, h float64)
Re appends a rectangle, of width w and height h, starting at the point (x, y), to the current path; re.
func (*ContentStream) Re2 ¶ added in v0.0.8
func (c *ContentStream) Re2(r Rect)
Re2 appends r to the current path; it is intended as a possibly more convenient version of Re.
func (*ContentStream) SVGArc ¶ added in v0.1.11
func (c *ContentStream) SVGArc(s SVGArcParams, h float64, m Matrix)
SVGArc draws an arc, represented in the SVG "endpoint parameterization" form, to c. The h and m parameters are the SVG's height and transformation matrix. This function should be avoided by most users.
func (*ContentStream) SetAlphaConst ¶ added in v0.0.18
func (c *ContentStream) SetAlphaConst(a float64, stroke bool)
SetAlphaConst sets c's nonstroking or stroking alpha constant to a, which must be a value in [0.0, 1.0], where 0 corresponds to full transparency and 1 corresponds to full opacity.
func (*ContentStream) SetCharSpace ¶ added in v0.0.11
func (c *ContentStream) SetCharSpace(f float64)
SetCharSpace sets the content stream's character spacing (c.TextState.CharSpace) f.
func (*ContentStream) SetColor ¶
func (c *ContentStream) SetColor(cl Color)
Sets c's nonstroking color (NColor) to cl and sets its NColorSpace to cl's ColorSpace.
func (*ContentStream) SetColorStroke ¶
func (c *ContentStream) SetColorStroke(cl Color)
Sets c's stroking color (SColor) to cl and sets its SColorSpace to cl's ColorSpace.
func (*ContentStream) SetDashPattern ¶ added in v0.0.4
func (c *ContentStream) SetDashPattern(d DashPattern)
Sets the dash pattern (c.GS.DashPattern) to d.
func (*ContentStream) SetExtGS ¶ added in v0.0.18
func (c *ContentStream) SetExtGS(extGState map[string]any)
SetExtGS sets c's graphic state to extGS. Use with caution, and refer to 8.4.5 / Table 57 of the PDF spec.
func (*ContentStream) SetFlatness ¶ added in v0.0.12
func (c *ContentStream) SetFlatness(f float64)
Set the flatness (c.GS.Flatness) to f.
func (*ContentStream) SetFont ¶ added in v0.0.11
func (c *ContentStream) SetFont(size float64, font *Font)
SetFont sets the current font size and font (c.TextState.Font and c.TextState.FontSize) to size and font.
func (*ContentStream) SetHScale ¶ added in v0.0.11
func (c *ContentStream) SetHScale(f float64)
SetHScale sets the content stream's horizontal text scaling percentage (c.TextState.Scale) to f. The default value is 100.0 percent.
func (*ContentStream) SetLeading ¶ added in v0.0.11
func (c *ContentStream) SetLeading(f float64)
SetLeading sets the content stream's text leading/line height (c.TextState.Leading) to f.
func (*ContentStream) SetLineCap ¶ added in v0.0.4
func (c *ContentStream) SetLineCap(lc LineCap)
Sets the line cap style (c.GS.LineCap) to lc.
func (*ContentStream) SetLineJoin ¶ added in v0.0.4
func (c *ContentStream) SetLineJoin(lj LineJoin)
Sets the line join style (c.GS.LineJoin) to lj.
func (*ContentStream) SetLineWidth ¶ added in v0.0.4
func (c *ContentStream) SetLineWidth(f float64)
Sets the line width (c.GS.LineWidth) to f.
func (*ContentStream) SetMiterLimit ¶ added in v0.0.4
func (c *ContentStream) SetMiterLimit(ml float64)
Sets miter limit (c.GS.MiterLimit) to ml.
func (*ContentStream) SetRenderIntent ¶ added in v0.0.4
func (c *ContentStream) SetRenderIntent(n string)
Sets the rendering intent (c.GS.RenderingIntent) to n.
func (*ContentStream) SetRenderMode ¶ added in v0.0.11
func (c *ContentStream) SetRenderMode(r RenderMode)
SetRenderMode sets the current text rendering mode (c.TextState.RenderMode) to r.
func (*ContentStream) SetRise ¶ added in v0.0.11
func (c *ContentStream) SetRise(f float64)
SetRise sets the current text rise (c.TextState.RenderMode) to f.
func (*ContentStream) SetTextMatrix ¶ added in v0.0.11
func (c *ContentStream) SetTextMatrix(m Matrix)
SetTextMatrix sets the current text object's text matrix and line matrix to m; Tm.
func (*ContentStream) SetTextOffset ¶ added in v0.1.4
func (c *ContentStream) SetTextOffset(x, y float64)
SetTextOffset offsets the current text object's text matrix by x and y, and sets the text object's line matrix equal to its text matrix.
func (*ContentStream) SetTextOffsetLeading ¶ added in v0.1.4
func (c *ContentStream) SetTextOffsetLeading(x, y float64)
SetTextOffsetLeading sets the content stream's current leading to y and then calls c.TextOffset(x, y).
func (*ContentStream) SetWordSpace ¶ added in v0.0.11
func (c *ContentStream) SetWordSpace(f float64)
SetWordSpace sets the content stream's word spacing (c.TextState.WordSpace) to f.
func (*ContentStream) ShowString ¶ added in v0.0.11
func (c *ContentStream) ShowString(s string)
ShowString writes s (without kerning) to c and advances the text matrix by the extent of s; Tj.
func (*ContentStream) ShowText ¶ added in v0.0.11
func (c *ContentStream) ShowText(t []rune, kerns []int) error
ShowText writes t (with kerning) to c and advances the text matrix by the extent of t; TJ.
func (*ContentStream) Stroke ¶ added in v0.0.3
func (c *ContentStream) Stroke()
Stroke strokes the path; S.
func (*ContentStream) TextCursor ¶
func (c *ContentStream) TextCursor() Point
TextCursor returns the x and y coordinates of the point (0,0,1) transformed by the current text matrix and the current transformation matrix.
type DashPattern ¶
type DefaultSubsetter ¶ added in v0.1.12
type DefaultSubsetter struct {
subset.BasicSubsetter
}
type EndText ¶ added in v0.0.4
type EndText func() error
An EndText function return by c.BeginText() must be invoked to close a section of text written to c.
type FillRule ¶ added in v0.0.18
type FillRule bool
A FillRule represents an algorithm for determining whether a particular point is interior to a path. See ISO 32000-2:2020 sections 8.5.3.3.2 and 8.5.3.3.3 for further details. NonZero is the default, but EvenOdd can produce results that are easier to intuit.
type Filter ¶
type Filter uint
A Filter is a compression algorithm that can compress internal PDF data.
type Font ¶
type Font struct { SFNT *sfnt.Font // The source TrueType or OpenType font. Subsetter FontSubsetter // contains filtered or unexported fields }
A Font represents an SFNT font. Any given Font struct should be used on at most 1 PDF. To use the same underlying font on multiple PDF files, derive a new Font struct from the source font file or bytes for each PDF.
func LoadSFNT ¶ added in v0.1.13
LoadSFNT returns a *Font object, which can be used for drawing text to a ContentStream or XObject, and an error.
func LoadSFNTFile ¶ added in v0.1.13
LoadSFNTFile returns a *Font object, which can be used for drawing text to a ContentStream or XObject, and an error.
func (*Font) AscDesc ¶ added in v0.1.0
AscDesc returns the ascent and descent, in font units, of the glyph corresponding to the given rune.
func (*Font) GlyphAdvance ¶ added in v0.1.0
GlyphAdvance returns the advance of r in font units.
func (*Font) ShapedGlyphAdv ¶ added in v0.1.0
ShapedGlyphAdv returns the advance and kerning of r1 when set before r2.
type FontSubsetter ¶ added in v0.1.12
type FontSubsetter interface { Init(SFNT *sfnt.Font, src []byte, path string) Subset(cutset map[rune]struct{}) ([]byte, error) }
A FontSubsetter is intended to give the user control over how a Font is subset when it is embedded in the output PDF. By default, gdf uses the DefaultSubsetter, which is equivalent to the BasicSubsetter type from github.com/cdillond/gdf/font, but there are good reasons to choose a different implementation (the gdf/font package provides several). For example, Harfbuzz's hb-subset tool and Microsoft's Win32 CreateFontPackage are robust alternatives written in C++ that can be wrapped by a user-defined FontSubsetter. If you do not want the embedded font to be subset at all, you can set the font's FontSubsetter to nil. A FontSubsetter should not alter the glyph ID of any rune in the cutset. It must also be sure to include a .notdef glyph.
type GS ¶
type GS struct { Matrix // Current Transformation Matrix TextState LineCap LineJoin DashPattern PathState CurPt Point // Current path point NColorSpace ColorSpace // nonstroking SColorSpace ColorSpace // stroking NColor Color // nonstroking SColor Color // stroking LineWidth float64 MiterLimit float64 RenderingIntent string StrokeAdj bool BlendMode string SoftMask string AlphaConstant float64 StrokeAlphaConstant float64 AlphaSource bool BPComp string Overprint bool OverprintMode uint BlackGen string UndercolorRem string Transfer string Halftone string Flatness float64 Smoothness float64 }
A GS struct represents a ContentStream's graphics state.
type Image ¶ added in v0.1.0
type Image struct { Data []byte Width int // The width of the image in pixels. Height int // The height of the image in pixels. ColorSpace ColorSpace BitsPerComponent int // The bit depth of the image's encoding. Alpha *Image // An image's alpha channel, if present, must be encoded as a separate image. The Alpha image's ColorSpace should be DeviceGray. AppliedFilter Filter // The filter used to pre-compress the image Data. RawDataLen int // The length (in bytes) of the uncompressed image Data; only needed if AppliedFilter is nonzero. // contains filtered or unexported fields }
An Image represents a raster image.
type InfoDict ¶ added in v0.0.15
type InfoDict struct { Title string Author string Subject string Keywords string Creator string Producer string CreationDate time.Time ModDate time.Time // contains filtered or unexported fields }
An InfoDict represents a PDF's document information dictionary, which describes document level metadata. The PDF 2.0 Specification deprecates the use of all InfoDict fields except CreationDate and ModDate in favor of XMP Metadata. Adding an InfoDict to a PDF therefore has the effect of setting the output PDF version to 1.7. Although this is feature deprecated for PDF 2.0, info dictionary metadata has broader support among PDF readers than XMP, and is the most common method for representing certain document properties.
type Margins ¶
type Margins struct {
Left, Right, Top, Bottom float64
}
Each field in a Margins struct represents an interior offset from the corresponding edge of a Rect.
type Matrix ¶
type Matrix struct { A float64 // X scale B float64 // X shear C float64 // Y shear D float64 // Y scale E float64 // X offset F float64 // Y offset }
A Matrix represents the first 2 columns of a 3-column affine transformation matrix, whose third column is always [0,0,1]. Matrices are used to represent transformations applied to an object's coordinate space by the PDF viewer. A ContentStream's Current Transformation Matrix (CTM, c.GS.Matrix) and text matrix (c.TextObj.Matrix) are the only two matrices within a PDF that gdf allows users to directly manipulate. CTMs can be altered by calling c.Concat(m). Text matrices are implicitly altered by any text showing operation, and can be explicitly set through calls to c.SetTextMatrix(m). Whereas Concat sets the CTM to the matrix product of m and the CTM, SetTextMatrix replaces the current text matrix with m.
func NewMatrix ¶
func NewMatrix() Matrix
NewMatrix returns a new instance of the Identity Matrix. This function should be used instead of Matrix{} or *new(Matrix), since empty matrices can result in undefined behavior. When combining transformations, the PDF spec's recommended order of operations is translate, rotate, scale or skew.
func Rotate ¶
Rotate returns a Matrix that represents the rotation of a coordinate space counter-clockwise about the origin by theta.
func ScaleBy ¶
ScaleBy returns a Matrix that represents the scaling of a coordinate space by scaleX and scaleY.
func Skew ¶
Skew returns a Matrix that represents the transformation of a coordinate space by skewing its x axis by xTheta and its y axis by yTheta.
type PDF ¶
type PDF struct {
// contains filtered or unexported fields
}
func (*PDF) AddXMPMetaData ¶ added in v0.0.8
Includes the XMP data represented by b as document-level metadata for the encoded PDF. Currently, gdf does not perform any validation on b.
func (*PDF) InsertPage ¶ added in v0.0.8
Inserts page at index i of the PDF's internal page structure.
func (*PDF) NewAcroField ¶ added in v0.0.15
All AcroFields should be created using the PDF.NewAcroField() method. Once an AcroField is created, it must be paired with a Widget and added to a Page that must, in turn, be appended to p.
func (*PDF) NewImage ¶ added in v0.1.0
NewImage returns an Image that can be drawn to ContentStreams derived from p.
func (*PDF) ReplacePage ¶ added in v0.0.8
ReplacePage replaces the page at index i of the PDF's internal page structure with page.
func (*PDF) SetLanguage ¶ added in v0.0.15
SetLanguage sets the default natural language of all text in the PDF to s, which must be a string representation of a valid BCP 47 language tag. (See golang.org/x/text/language). NOTE: gdf currently only supports Windows-1252 ("WinAnsiEncoding") for most textual elements in a PDF document. Text that appears in annotations may represent a wider range of characters, depending on the reader used to view the PDF.
func (*PDF) SetViewPrefs ¶ added in v0.0.15
SetViewPrefs indicates the desired display settings for the PDF viewer to use when displaying p.
type Page ¶
type Page struct { MediaBox Rect CropBox Rect // "the rectangle of user space corresponding to the visible area of the intended output medium (display window or printed page)" Margins // contains filtered or unexported fields }
func (*Page) AddAcroField ¶ added in v0.0.15
AddAcroField adds an AcroField, whose visible component is w, to p. dst specifies the area of p's user space onto which w is drawn. If strokeBorder is true, dst is added to the page's path, and the border is stroked with the current stroke width and stroke color. Once f has been added to p, p must be appended to the PDF from which f was derived prior to the invocation of PDF.WriteTo().
func (*Page) Annotate ¶ added in v0.0.15
Annotate draws the TextAnnot t to the area of p described by r.
func (Page) ContentStream ¶ added in v0.1.5
func (p Page) ContentStream() *ContentStream
ContentStream returns a pointer to p's ContentStream.
type PathState ¶
type PathState uint
A PathState represents a ContentStream's current path operations state.
type Point ¶
type Point struct {
X, Y float64
}
Point represents a Point. All Points implicitly include a Z coordinate of 1.
type Rect ¶
type Rect struct {
LLX, LLY, URX, URY float64
}
A Rect represents a rectangular area of a coordinate space, where (LLX, LLY) is the lower left vertex and (URX, URY) is the upper right vertex.
func NewRect ¶ added in v0.0.13
NewRect returns a Rect where ll is the lower left vertex and ur is the upper right vertex.
func (Rect) Angles ¶ added in v0.0.5
Angles returns the angle, in radians, formed by the lower side of the rectangle and the lower-left to upper-right diagonal, and that angle's complement.
func (Rect) Bounds ¶ added in v0.0.11
Bounds returns the Rect that results from applying m to r without checking whether that Rect is valid.
type RenderMode ¶
type RenderMode uint
const ( FillText RenderMode = iota StrokeText FillStrokeText Invisible FillTextAddPath StrokeTextAddPath FillStrokeTextAddPath AddTextPath )
type SVGArcParams ¶ added in v0.1.11
type SVGArcParams struct {
X1, Y1 float64 // x and y coordinates of the start point in SVG user space
Rx, Ry float64 // size of the x and y radii
Phi float64 // x-axis rotation angle in radians
IsLong bool // determines the size of the arc angle
IsClockwise bool // determines the drawing direction
X2, Y2 float64 // x and y coordinates of the end point in SVG user space
}
SVGArcParams represents the "endpoint parameterization" of an SVG arc subpath.
type TextAnnot ¶ added in v0.0.15
type TextAnnot struct { Contents string // Text to be displayed by the annotation. User string // Name of the user creating the comment. ModDate time.Time CreationDate time.Time Subject string Open bool Name string // Unique annotation name. Flags annotFlag IconStyle textAnnotStyle Appearance *XContent // Optional; if nil the IconStyle is used; overrides the IconStyle if non-nil. Color // contains filtered or unexported fields }
A TextAnnot is text that appears in a pop-up when the user hovers over the annotated area of a page. The Appearance *XObject, if provided, describes the appearance of the TextAnnot's note icon, which is normally always visible on the viewed page. The Color field specifies the color of the pop-up annotation.
type ViewPrefs ¶ added in v0.0.15
type ViewPrefs struct { HideToolbar bool HideMenu bool HideWindowUI bool FitWindow bool CenterWindow bool DisplayDocTitle bool NonFullScreenPageMode bool Direction preference PrintScaling preference Duplex preference PrintPageRange []PageRange NumCopies uint }
A ViewPrefs struct can be used to configure details of how the PDF viewer handles the output file.
type Widget ¶ added in v0.0.15
type Widget struct { AcroType acroType Flags annotFlag // 12.5.3 annotation flags User string ModDate time.Time CreationDate time.Time Subject string Open bool Name string // unique text string identifying the Widget Opts []string // contains filtered or unexported fields }
A Widget is an annotation that serves as the visible representation of an interactive acroform field.
func NewWidget ¶ added in v0.0.15
func NewWidget(cfg WidgetCfger) *Widget
NewWidget returns a new *Widget as configured by cfg.
type WidgetCfger ¶ added in v0.0.15
type WidgetCfger interface {
// contains filtered or unexported methods
}
WidgetCfger is an interface used to configure Widgets and their associated AcroFields. It is implemented by AcroTextCfg and CheckboxCfg.
type XContent ¶ added in v0.1.0
type XContent struct { ContentStream BBox Rect }
An XContent struct represents a PDF form-type XObject. It is essentially a ContentStream that can be displayed by multiple Pages of a PDF.
func NewXContent ¶ added in v0.1.0
type XImage ¶ added in v0.0.15
type XImage struct { Data []byte Width int // The width of the image in pixels. Height int // The height of the image in pixels. ColorSpace ColorSpace BitsPerComponent int // The bit depth of the image's encoding. AppliedFilter Filter // The filter used to pre-compress the image Data. RawDataLen int // The length (in bytes) of the uncompressed image Data; only needed if AppliedFilter is nonzero. Alpha *XImage }
An XImage represents an image that is external to any given PDF.
func LoadXImage ¶ added in v0.1.0
LoadXImage reads a gob-encoded XImage from r.
func (*XImage) FlateCompress ¶ added in v0.1.0
FlateCompress compresses x's Data using the Flate filter, and updates the XImage to indicate that the filter has been applied. Most images (except JPEGs) are compressed using this filter automatically when the output PDF file is written. However, completing the process ahead of time by calling FlateCompress and then re-using a pre-decoded and pre-compressed XImage can be significantly more efficient.
Source Files ¶
- acroform.go
- annot.go
- arc.go
- arcsvg.go
- catalog.go
- checkbox.go
- color.go
- cs.go
- extent.go
- extgs.go
- filter.go
- font.go
- fontutils.go
- format.go
- gdf.go
- gs.go
- img.go
- info.go
- matrix.go
- metadata.go
- object.go
- ops.go
- page.go
- pages.go
- path.go
- stream.go
- textobj.go
- textstate.go
- units.go
- viewer.go
- widget.go
- write.go
- xobj.go