doc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	BlendNormal     = style.BlendNormal
	BlendMultiply   = style.BlendMultiply
	BlendScreen     = style.BlendScreen
	BlendOverlay    = style.BlendOverlay
	BlendDarken     = style.BlendDarken
	BlendLighten    = style.BlendLighten
	BlendColorDodge = style.BlendColorDodge
	BlendColorBurn  = style.BlendColorBurn
	BlendHardLight  = style.BlendHardLight
	BlendSoftLight  = style.BlendSoftLight
	BlendDifference = style.BlendDifference
	BlendExclusion  = style.BlendExclusion
)
View Source
const (
	LineCapButt   = style.LineCapButt
	LineCapRound  = style.LineCapRound
	LineCapSquare = style.LineCapSquare
	LineJoinMiter = style.LineJoinMiter
	LineJoinRound = style.LineJoinRound
	LineJoinBevel = style.LineJoinBevel
)
View Source
const (
	TextAlignLeft    = text.AlignLeft
	TextAlignCenter  = text.AlignCenter
	TextAlignRight   = text.AlignRight
	TextAlignJustify = text.AlignJustify
)
View Source
const (
	CellVAlignTop    = table.CellVAlignTop
	CellVAlignMiddle = table.CellVAlignMiddle
	CellVAlignBottom = table.CellVAlignBottom

	CellHAlignLeft    = table.CellHAlignLeft
	CellHAlignCenter  = table.CellHAlignCenter
	CellHAlignRight   = table.CellHAlignRight
	CellHAlignJustify = table.CellHAlignJustify
)

Variables

View Source
var (
	ColorBlack     = style.Black
	ColorWhite     = style.White
	ColorRed       = style.Red
	ColorGreen     = style.Green
	ColorBlue      = style.Blue
	ColorGray      = style.GrayColor
	ColorLightGray = style.LightGray
	ColorDarkGray  = style.DarkGray
	ColorOrange    = style.Orange
	ColorYellow    = style.Yellow
	ColorPurple    = style.Purple
	ColorCyan      = style.Cyan
	ColorMagenta   = style.Magenta
	ColorPink      = style.Pink
	ColorBrown     = style.Brown
	ColorTeal      = style.Teal
	ColorNavy      = style.Navy
	ColorMaroon    = style.Maroon
	ColorOlive     = style.Olive
	ColorSilver    = style.Silver
	ColorLime      = style.Lime
)
View Source
var ColorFromHex = style.ColorFromHex
View Source
var ColorGray50 = style.Gray
View Source
var NewICCProfile = style.NewICCProfile
View Source
var SRGBProfile = style.SRGBProfile

Functions

This section is empty.

Types

type BlendMode

type BlendMode = style.BlendMode

type CatalogReader

type CatalogReader interface {
	Catalog() (*model.Catalog, error)
	Pages() ([]model.Page, error)
	Info() (model.Dict, error)
	MetadataStream() ([]byte, error)
	StartXRefOffset() int64
	Trailer() model.Trailer
}

CatalogReader provides access to the document catalog, page tree, info dict, and metadata.

type CellHorizontalAlign

type CellHorizontalAlign = table.CellHorizontalAlign

type CellStyle

type CellStyle = table.CellStyle

type CellVerticalAlign

type CellVerticalAlign = table.CellVerticalAlign

type Color

type Color = style.Color

type ContentReader

type ContentReader interface {
	ReadContent() (string, error)
	ReadContentPerPage() ([]string, error)
}

ContentReader extracts text content from a PDF document.

type ContentSearcher

type ContentSearcher interface {
	Search(keywords ...string) ([]model.SearchResult, error)
	Replace(old, new string) error
	Replaces(replacements map[string]string) error
}

ContentSearcher searches for keywords and replaces text within content streams.

type Document

Document is the main interface for a PDF document (opened or built). It composes focused sub-interfaces for catalog access, content reading, search/replace, image extraction, layout analysis, and saving.

func Merge

func Merge(docs ...Document) (Document, error)

Merge combines multiple documents into a single new document. Pages from the documents are appended in the order they are provided.

Example
package main

import (
	"log"
	"os"

	"github.com/gsoultan/gpdf/doc"
)

func main() {
	// Open the first document
	doc1, err := doc.Open("file1.pdf")
	if err != nil {
		log.Fatalf("Failed to open file1.pdf: %v", err)
	}
	defer doc1.Close()

	// Open the second document
	doc2, err := doc.Open("file2.pdf")
	if err != nil {
		log.Fatalf("Failed to open file2.pdf: %v", err)
	}
	defer doc2.Close()

	// Merge the documents
	merged, err := doc.Merge(doc1, doc2)
	if err != nil {
		log.Fatalf("Failed to merge documents: %v", err)
	}
	defer merged.Close()

	// Save the merged document to a new file
	f, err := os.Create("merged.pdf")
	if err != nil {
		log.Fatalf("Failed to create merged.pdf: %v", err)
	}
	defer f.Close()

	if err := merged.Save(f); err != nil {
		log.Fatalf("Failed to save merged document: %v", err)
	}
}

func Open

func Open(path string) (Document, error)

Open opens an existing PDF from path and returns a Document.

func OpenReader

func OpenReader(r io.ReaderAt, size int64) (Document, error)

OpenReader opens an existing PDF from a random-access reader and returns a Document.

func OpenReaderWithPassword

func OpenReaderWithPassword(r io.ReaderAt, size int64, userPassword string) (Document, error)

OpenReaderWithPassword opens an existing PDF from a random-access reader and decrypts it with the user password if encrypted.

func OpenWithPassword

func OpenWithPassword(path string, userPassword string) (Document, error)

OpenWithPassword opens an existing PDF from path and decrypts it with the user password if encrypted.

type DocumentBuilder

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

DocumentBuilder builds a new PDF via a fluent API. Call Build() to produce a Document. It is a thin facade that delegates drawing operations to sub-builders.

func New

func New() *DocumentBuilder

New returns a new DocumentBuilder for constructing a PDF from scratch. Sub-builders are initialized for text, graphics, and image drawing.

func (*DocumentBuilder) A3

A3 sets the page size to A3 (297 x 420 mm).

func (*DocumentBuilder) A4

A4 sets the page size to A4 (210 x 297 mm).

func (*DocumentBuilder) A5

A5 sets the page size to A5 (148 x 210 mm).

func (*DocumentBuilder) AddCheckBox

func (b *DocumentBuilder) AddCheckBox(pageIndex int, llx, lly, urx, ury float64, name string, checked bool, tooltip string, required bool) *DocumentBuilder

AddCheckBox adds a checkbox form field (/FT /Btn) with a single widget annotation.

func (*DocumentBuilder) AddLinkToDest

func (b *DocumentBuilder) AddLinkToDest(pageIndex int, llx, lly, urx, ury float64, destName string) *DocumentBuilder

AddLinkToDest adds a link annotation on a page linking to a named destination.

func (*DocumentBuilder) AddLinkToPage

func (b *DocumentBuilder) AddLinkToPage(pageIndex int, llx, lly, urx, ury float64, destPageIndex int) *DocumentBuilder

AddLinkToPage adds a link annotation on a page linking to another page.

func (*DocumentBuilder) AddLinkToURL

func (b *DocumentBuilder) AddLinkToURL(pageIndex int, llx, lly, urx, ury float64, url string) *DocumentBuilder

AddLinkToURL adds a link annotation on a page opening a URL.

func (*DocumentBuilder) AddNamedDest

func (b *DocumentBuilder) AddNamedDest(name string, pageIndex int) *DocumentBuilder

AddNamedDest registers a named destination for the page at 0-based pageIndex.

func (*DocumentBuilder) AddOutline

func (b *DocumentBuilder) AddOutline(title string, pageIndex int) *DocumentBuilder

AddOutline adds a document outline (bookmark) linking to the given page.

func (*DocumentBuilder) AddOutlineToDest

func (b *DocumentBuilder) AddOutlineToDest(title string, destName string) *DocumentBuilder

AddOutlineToDest adds an outline entry that goes to the named destination.

func (*DocumentBuilder) AddOutlineURL

func (b *DocumentBuilder) AddOutlineURL(title string, url string) *DocumentBuilder

AddOutlineURL adds an outline entry that opens the given URL.

func (*DocumentBuilder) AddPage

func (b *DocumentBuilder) AddPage() *DocumentBuilder

AddPage adds a blank page with the current default page size.

func (*DocumentBuilder) AddRadioButton

func (b *DocumentBuilder) AddRadioButton(pageIndex int, llx, lly, urx, ury float64, groupName, value string, checked bool, tooltip string) *DocumentBuilder

AddRadioButton adds a single radio button belonging to a logical group. Radio buttons in the same groupName share one /FT /Btn field with multiple widgets.

func (*DocumentBuilder) AddSubmitButton

func (b *DocumentBuilder) AddSubmitButton(pageIndex int, llx, lly, urx, ury float64, name, label, submitURL, tooltip string) *DocumentBuilder

AddSubmitButton adds a pushbutton with a simple SubmitForm action to the given URL.

func (*DocumentBuilder) AddTable

func (b *DocumentBuilder) AddTable(pageIndex int) int

func (*DocumentBuilder) AddTableCell

func (b *DocumentBuilder) AddTableCell(tableIndex, rowIndex, pageIndex int, role model.Name, scope, alt, lang string, mcids []int)

func (*DocumentBuilder) AddTextField

func (b *DocumentBuilder) AddTextField(pageIndex int, llx, lly, urx, ury float64, name, value, tooltip string, required bool) *DocumentBuilder

AddTextField adds a text form field (/FT /Tx) with an associated widget annotation on the given page. The rectangle is in user space (llx, lly, urx, ury). name is the field name; value is the default value.

func (*DocumentBuilder) AppendPage

func (b *DocumentBuilder) AppendPage()

func (*DocumentBuilder) ApplyPageSize

func (b *DocumentBuilder) ApplyPageSize(sz pagesize.Size) *DocumentBuilder

ApplyPageSize sets the default page size from a predefined Size preset.

func (*DocumentBuilder) Author

func (b *DocumentBuilder) Author(s string) *DocumentBuilder

Author sets the document author (Info /Author).

func (*DocumentBuilder) B4JIS

func (b *DocumentBuilder) B4JIS() *DocumentBuilder

B4JIS sets the page size to B4 (JIS) (257 x 364 mm).

func (*DocumentBuilder) B5JIS

func (b *DocumentBuilder) B5JIS() *DocumentBuilder

B5JIS sets the page size to B5 (JIS) (182 x 257 mm).

func (*DocumentBuilder) BeginLayer

func (b *DocumentBuilder) BeginLayer(name string, onByDefault bool) *layer.Handle

BeginLayer starts drawing into a named optional content group (OCG). All subsequent drawing operations on the given pageIndex will be wrapped in a marked-content block associated with the OCG until EndLayer is called. When the layer does not yet exist, it is created and added to the document's OCProperties; repeated calls with the same name reuse the same OCG.

func (*DocumentBuilder) BeginPath

func (b *DocumentBuilder) BeginPath(pageIndex int) *PathBuilder

BeginPath starts a custom path on the given page. Use MoveTo, LineTo, CurveTo, Rect, ClosePath to construct the path, then Stroke, Fill, FillStroke, or EndPath to finish.

func (*DocumentBuilder) BeginSection

func (b *DocumentBuilder) BeginSection() *DocumentBuilder

BeginSection starts a logical section for tagged content.

func (*DocumentBuilder) BeginTable

func (b *DocumentBuilder) BeginTable(pageIndex int, x, y, width, height float64, cols int) ITableBuilder

BeginTable starts a tagged table region on the given page at (x, y) with the given size and number of columns.

func (*DocumentBuilder) Build

func (b *DocumentBuilder) Build() (Document, error)

Build returns a Document that can be saved. The document is in-memory.

func (*DocumentBuilder) BuildAndSave

func (b *DocumentBuilder) BuildAndSave(path string) error

BuildAndSave builds the document and saves it to the specified path.

func (*DocumentBuilder) Creator

func (b *DocumentBuilder) Creator(s string) *DocumentBuilder

Creator sets the application that created the document (Info /Creator).

func (*DocumentBuilder) CurrentPage

func (b *DocumentBuilder) CurrentPage() *Page

CurrentPage returns a Page object for the last added page.

func (*DocumentBuilder) CurrentSection

func (b *DocumentBuilder) CurrentSection() int

func (*DocumentBuilder) DrawCircle

func (b *DocumentBuilder) DrawCircle(pageIndex int, cx, cy, radius float64, style LineStyle) *DocumentBuilder

DrawCircle draws a stroked circle centered at (cx, cy) with the given radius.

func (*DocumentBuilder) DrawCircleWithState

func (b *DocumentBuilder) DrawCircleWithState(pageIndex int, cx, cy, radius float64, style LineStyle, state GraphicsState) *DocumentBuilder

DrawCircleWithState draws a stroked circle with the given graphics state.

func (*DocumentBuilder) DrawCircularImage

func (b *DocumentBuilder) DrawCircularImage(x, y, widthPt, heightPt float64, raw []byte, widthPx, heightPx, bitsPerComponent int, colorSpace string, cx, cy, radius float64) *DocumentBuilder

DrawCircularImage queues a raw image clipped to a circle on the last added page.

func (*DocumentBuilder) DrawCircularJPEG

func (b *DocumentBuilder) DrawCircularJPEG(x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string, cx, cy, radius float64) *DocumentBuilder

DrawCircularJPEG queues a JPEG image clipped to a circle on the last added page.

func (*DocumentBuilder) DrawCircularPNG

func (b *DocumentBuilder) DrawCircularPNG(x, y, widthPt, heightPt float64, pngData []byte, cx, cy, radius float64) *DocumentBuilder

DrawCircularPNG decodes a PNG and draws it clipped to a circle on the last added page.

func (*DocumentBuilder) DrawEllipse

func (b *DocumentBuilder) DrawEllipse(pageIndex int, cx, cy, rx, ry float64, style LineStyle) *DocumentBuilder

DrawEllipse strokes an axis-aligned ellipse centered at (cx, cy) with semi-axes rx and ry.

func (*DocumentBuilder) DrawEllipseWithState

func (b *DocumentBuilder) DrawEllipseWithState(pageIndex int, cx, cy, rx, ry float64, style LineStyle, state GraphicsState) *DocumentBuilder

DrawEllipseWithState draws a stroked ellipse with graphics state.

func (*DocumentBuilder) DrawHeading

func (b *DocumentBuilder) DrawHeading(pageIndex int, level int, textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawHeading queues a tagged heading (/H1..H6) on the given page at (x, y). Level must be in [1,6]; values outside this range are clamped.

func (*DocumentBuilder) DrawHeadingColored

func (b *DocumentBuilder) DrawHeadingColored(pageIndex int, level int, textStr string, x, y float64, fontName string, fontSize float64, color Color) *DocumentBuilder

DrawHeadingColored behaves like DrawHeading but sets the text color.

func (*DocumentBuilder) DrawImage

func (b *DocumentBuilder) DrawImage(x, y, widthPt, heightPt float64, raw []byte, widthPx, heightPx, bitsPerComponent int, colorSpace string) *DocumentBuilder

DrawImage queues an image to be drawn on the last added page at (x, y) with display size (widthPt, heightPt). Raw is the decoded image stream; widthPx/heightPx and bitsPerComponent/colorSpace must match. colorSpace should be DeviceGray, DeviceRGB, or DeviceCMYK. Call after AddPage().

func (*DocumentBuilder) DrawImageWith

func (b *DocumentBuilder) DrawImageWith(opts ImageOptions) *DocumentBuilder

DrawImageWith queues an image using the options struct.

func (*DocumentBuilder) DrawImageWithOpacity

func (b *DocumentBuilder) DrawImageWithOpacity(x, y, widthPt, heightPt float64, raw []byte, widthPx, heightPx, bitsPerComponent int, colorSpace string, opacity float64) *DocumentBuilder

DrawImageWithOpacity queues a raw image drawn at (x,y) with the given opacity in [0,1].

func (*DocumentBuilder) DrawInLayer

func (b *DocumentBuilder) DrawInLayer(lh *layer.Handle, pageIndex int, draw func(db *DocumentBuilder)) *DocumentBuilder

DrawInLayer wraps a drawing function so that all content it emits on the given page is associated with the specified layer.

func (*DocumentBuilder) DrawJPEG

func (b *DocumentBuilder) DrawJPEG(x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string) *DocumentBuilder

DrawJPEG queues a JPEG image to be drawn on the last added page at (x, y) with display size (widthPt, heightPt). jpegData is the raw JPEG file bytes (not decoded); widthPx/heightPx must match the JPEG dimensions.

func (*DocumentBuilder) DrawJPEGRotated

func (b *DocumentBuilder) DrawJPEGRotated(x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string, rotateDeg float64) *DocumentBuilder

DrawJPEGRotated queues a JPEG image rotated clockwise by rotateDeg degrees.

func (*DocumentBuilder) DrawJPEGWithOpacity

func (b *DocumentBuilder) DrawJPEGWithOpacity(x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string, opacity float64) *DocumentBuilder

DrawJPEGWithOpacity queues a JPEG image drawn at (x,y) with the given opacity in [0,1].

func (*DocumentBuilder) DrawLine

func (b *DocumentBuilder) DrawLine(pageIndex int, x1, y1, x2, y2 float64, style LineStyle) *DocumentBuilder

DrawLine draws a straight line from (x1, y1) to (x2, y2) on the given page.

func (*DocumentBuilder) DrawLineWithState

func (b *DocumentBuilder) DrawLineWithState(pageIndex int, x1, y1, x2, y2 float64, style LineStyle, state GraphicsState) *DocumentBuilder

DrawLineWithState draws a line with the given graphics state (e.g. opacity/blend mode).

func (*DocumentBuilder) DrawList

func (b *DocumentBuilder) DrawList(pageIndex int, items []string, x, y, lineHeight float64, ordered bool, fontName string, fontSize float64) *DocumentBuilder

DrawList queues a tagged list (/L with /LI children) on the given page. Items are rendered vertically starting at (x, y) with the given lineHeight (or a default when <= 0). When ordered is true, items are prefixed with "1. ", "2. ", ...; otherwise a bullet "• " is used.

func (*DocumentBuilder) DrawListEnhanced

func (b *DocumentBuilder) DrawListEnhanced(pageIndex int, items []string, x, y, lineHeight float64, ls style.ListStyle) *DocumentBuilder

DrawListEnhanced renders a list with advanced styling options.

func (*DocumentBuilder) DrawPNG

func (b *DocumentBuilder) DrawPNG(x, y, widthPt, heightPt float64, pngData []byte) *DocumentBuilder

DrawPNG decodes a PNG image and draws it on the last added page at (x, y) with display size (widthPt, heightPt).

func (*DocumentBuilder) DrawPNGRotated

func (b *DocumentBuilder) DrawPNGRotated(x, y, widthPt, heightPt float64, pngData []byte, rotateDeg float64) *DocumentBuilder

DrawPNGRotated decodes a PNG and draws it rotated clockwise by rotateDeg degrees.

func (*DocumentBuilder) DrawPNGWithOpacity

func (b *DocumentBuilder) DrawPNGWithOpacity(x, y, widthPt, heightPt float64, pngData []byte, opacity float64) *DocumentBuilder

DrawPNGWithOpacity decodes a PNG and draws it at (x,y) with the given opacity in [0,1].

func (*DocumentBuilder) DrawParagraph

func (b *DocumentBuilder) DrawParagraph(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawParagraph queues a tagged paragraph (/P) on the given page at (x, y). The text is associated with a structure element so it participates in Tagged PDF reading order.

func (*DocumentBuilder) DrawPolygon

func (b *DocumentBuilder) DrawPolygon(pageIndex int, points []float64, style LineStyle) *DocumentBuilder

DrawPolygon strokes a closed polygon defined by a list of (x,y) point pairs.

func (*DocumentBuilder) DrawPolygonWithState

func (b *DocumentBuilder) DrawPolygonWithState(pageIndex int, points []float64, style LineStyle, state GraphicsState) *DocumentBuilder

DrawPolygonWithState draws a stroked polygon with graphics state.

func (*DocumentBuilder) DrawRect

func (b *DocumentBuilder) DrawRect(pageIndex int, x, y, width, height float64, style LineStyle) *DocumentBuilder

DrawRect draws a stroked rectangle at (x, y) with dimensions width × height.

func (*DocumentBuilder) DrawRectWithState

func (b *DocumentBuilder) DrawRectWithState(pageIndex int, x, y, width, height float64, style LineStyle, state GraphicsState) *DocumentBuilder

DrawRectWithState draws a stroked rectangle with the given graphics state.

func (*DocumentBuilder) DrawRichText

func (b *DocumentBuilder) DrawRichText(pageIndex int, rt *RichText, x, y float64) *DocumentBuilder

DrawRichText renders styled rich text on the given page starting at (x, y). It automatically calculates the horizontal position for each segment.

func (*DocumentBuilder) DrawRoundedRect

func (b *DocumentBuilder) DrawRoundedRect(pageIndex int, x, y, width, height, radius float64, style LineStyle) *DocumentBuilder

DrawRoundedRect strokes a rectangle with rounded corners.

func (*DocumentBuilder) DrawRoundedRectWithState

func (b *DocumentBuilder) DrawRoundedRectWithState(pageIndex int, x, y, width, height, radius float64, style LineStyle, state GraphicsState) *DocumentBuilder

DrawRoundedRectWithState draws a stroked rounded rectangle with graphics state.

func (*DocumentBuilder) DrawTaggedCaption

func (b *DocumentBuilder) DrawTaggedCaption(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawTaggedCaption queues a tagged caption (/Caption) — e.g. for figure or table captions.

func (*DocumentBuilder) DrawTaggedCode

func (b *DocumentBuilder) DrawTaggedCode(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawTaggedCode queues a single-line tagged code (/Code) — e.g. inline or one-line code.

func (*DocumentBuilder) DrawTaggedCodeBlock

func (b *DocumentBuilder) DrawTaggedCodeBlock(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder

DrawTaggedCodeBlock lays out wrapped text as a tagged code block (/Code).

func (*DocumentBuilder) DrawTaggedFigure

func (b *DocumentBuilder) DrawTaggedFigure(pageIndex int, x, y, widthPt, heightPt float64, raw []byte, widthPx, heightPx, bitsPerComponent int, colorSpace string, alt string) *DocumentBuilder

DrawTaggedFigure draws an image as a tagged Figure with alternative text for accessibility.

func (*DocumentBuilder) DrawTaggedImageWith

func (b *DocumentBuilder) DrawTaggedImageWith(opts ImageOptions) *DocumentBuilder

DrawTaggedImageWith queues a tagged image using the options struct.

func (*DocumentBuilder) DrawTaggedJPEG

func (b *DocumentBuilder) DrawTaggedJPEG(pageIndex int, x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string, alt string) *DocumentBuilder

DrawTaggedJPEG draws a JPEG image as a tagged Figure with alternative text.

func (*DocumentBuilder) DrawTaggedPNG

func (b *DocumentBuilder) DrawTaggedPNG(pageIndex int, x, y, widthPt, heightPt float64, pngData []byte, alt string) *DocumentBuilder

DrawTaggedPNG decodes a PNG and draws it as a tagged Figure with alternative text.

func (*DocumentBuilder) DrawTaggedParagraphBox

func (b *DocumentBuilder) DrawTaggedParagraphBox(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder

DrawTaggedParagraphBox behaves like DrawTextBox but creates a tagged paragraph (/P) in the structure tree. The resulting text runs participate in Tagged PDF reading order.

func (*DocumentBuilder) DrawTaggedQuote

func (b *DocumentBuilder) DrawTaggedQuote(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawTaggedQuote queues a single-line tagged block quote (/Quote).

func (*DocumentBuilder) DrawTaggedQuoteBox

func (b *DocumentBuilder) DrawTaggedQuoteBox(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder

DrawTaggedQuoteBox lays out wrapped text as a tagged block quote (/Quote).

func (*DocumentBuilder) DrawText

func (b *DocumentBuilder) DrawText(textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawText queues text to be drawn on the last added page at (x, y) using the given font and size. FontName should be a standard PDF base font (e.g. Helvetica, Times-Roman). Call after AddPage().

func (*DocumentBuilder) DrawTextBox

func (b *DocumentBuilder) DrawTextBox(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder

DrawTextBox lays out text within a horizontal box on the given page. Text is wrapped to fit within opts.Width using a simple width heuristic based on fontSize. Alignment, line height, and optional multi-page continuation are controlled via opts. When opts.Width <= 0 or pageIndex is out of range, the call is a no-op.

func (*DocumentBuilder) DrawTextBoxColored

func (b *DocumentBuilder) DrawTextBoxColored(pageIndex int, textStr string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions, color Color) *DocumentBuilder

DrawTextBoxColored lays out wrapped text like DrawTextBox but renders each line in the given color.

func (*DocumentBuilder) DrawTextCentered

func (b *DocumentBuilder) DrawTextCentered(textStr string, cx, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawTextCentered draws text horizontally centered around the point (cx, y). The text baseline is at y; cx is the horizontal center of the rendered text.

func (*DocumentBuilder) DrawTextCenteredColored

func (b *DocumentBuilder) DrawTextCenteredColored(textStr string, cx, y float64, fontName string, fontSize float64, color Color, letterSpacing float64) *DocumentBuilder

DrawTextCenteredColored draws colored text horizontally centered around the point (cx, y).

func (*DocumentBuilder) DrawTextColored

func (b *DocumentBuilder) DrawTextColored(textStr string, x, y float64, fontName string, fontSize float64, color Color) *DocumentBuilder

DrawTextColored queues text drawn in the specified RGB color on the last added page. It behaves like DrawText but sets the fill color for that run.

func (*DocumentBuilder) DrawTextRight

func (b *DocumentBuilder) DrawTextRight(textStr string, x, y float64, fontName string, fontSize float64) *DocumentBuilder

DrawTextRight draws text right-aligned so that its right edge is at x.

func (*DocumentBuilder) DrawTextRightColored

func (b *DocumentBuilder) DrawTextRightColored(textStr string, x, y float64, fontName string, fontSize float64, color Color, letterSpacing float64) *DocumentBuilder

DrawTextRightColored draws colored text right-aligned so that its right edge is at x.

func (*DocumentBuilder) DrawTextRotated

func (b *DocumentBuilder) DrawTextRotated(textStr string, x, y float64, fontName string, fontSize float64, color Color, deg float64) *DocumentBuilder

DrawTextRotated draws text at (x, y) rotated by deg degrees counter-clockwise. It uses DrawTextWithSpacingScale defaults (letterSpacing=0, wordSpacing=0, horizontalScale=100).

func (*DocumentBuilder) DrawTextWithSpacing

func (b *DocumentBuilder) DrawTextWithSpacing(textStr string, x, y float64, fontName string, fontSize float64, color Color, letterSpacing, wordSpacing float64) *DocumentBuilder

DrawTextWithSpacing draws text at (x, y) with explicit color, letter and word spacing. This is useful for reconstructing PDFs where Tc/Tw were used and must be preserved.

func (*DocumentBuilder) DrawTextWithSpacingScale

func (b *DocumentBuilder) DrawTextWithSpacingScale(textStr string, x, y float64, fontName string, fontSize float64, color Color, letterSpacing, wordSpacing, horizontalScale float64) *DocumentBuilder

DrawTextWithSpacingScale is like DrawTextWithSpacing but also sets HorizontalScale (Tz percent).

func (*DocumentBuilder) DrawTextWithStrikethrough

func (b *DocumentBuilder) DrawTextWithStrikethrough(textStr string, x, y float64, fontName string, fontSize float64, color Color) *DocumentBuilder

DrawTextWithStrikethrough draws text with a strikethrough line on the last added page.

func (*DocumentBuilder) DrawTextWithUnderline

func (b *DocumentBuilder) DrawTextWithUnderline(textStr string, x, y float64, fontName string, fontSize float64, color Color) *DocumentBuilder

DrawTextWithUnderline draws text with an underline on the last added page.

func (*DocumentBuilder) EndSection

func (b *DocumentBuilder) EndSection() *DocumentBuilder

EndSection ends the current section started by BeginSection.

func (*DocumentBuilder) EnsureTableRow

func (b *DocumentBuilder) EnsureTableRow(tableIndex, rowIndex int, rowHeight float64)

func (*DocumentBuilder) Err

func (b *DocumentBuilder) Err() error

Err returns the first error recorded during building. Check after Build() or before further fluent calls.

func (*DocumentBuilder) Executive

func (b *DocumentBuilder) Executive() *DocumentBuilder

Executive sets the page size to Executive (7.25 x 10.5 in).

func (*DocumentBuilder) FillCircle

func (b *DocumentBuilder) FillCircle(pageIndex int, cx, cy, radius float64, fill Color) *DocumentBuilder

FillCircle draws a filled circle centered at (cx, cy) with the given radius.

func (*DocumentBuilder) FillCircleWithState

func (b *DocumentBuilder) FillCircleWithState(pageIndex int, cx, cy, radius float64, fill Color, state GraphicsState) *DocumentBuilder

FillCircleWithState draws a filled circle with the given graphics state.

func (*DocumentBuilder) FillEllipse

func (b *DocumentBuilder) FillEllipse(pageIndex int, cx, cy, rx, ry float64, fill Color) *DocumentBuilder

FillEllipse fills an axis-aligned ellipse centered at (cx, cy) with semi-axes rx and ry.

func (*DocumentBuilder) FillEllipseWithState

func (b *DocumentBuilder) FillEllipseWithState(pageIndex int, cx, cy, rx, ry float64, fill Color, state GraphicsState) *DocumentBuilder

FillEllipseWithState draws a filled ellipse with graphics state.

func (*DocumentBuilder) FillPolygon

func (b *DocumentBuilder) FillPolygon(pageIndex int, points []float64, fill Color) *DocumentBuilder

FillPolygon fills a closed polygon defined by a list of (x,y) point pairs.

func (*DocumentBuilder) FillPolygonWithState

func (b *DocumentBuilder) FillPolygonWithState(pageIndex int, points []float64, fill Color, state GraphicsState) *DocumentBuilder

FillPolygonWithState draws a filled polygon with graphics state.

func (*DocumentBuilder) FillRect

func (b *DocumentBuilder) FillRect(pageIndex int, x, y, width, height float64, fill Color) *DocumentBuilder

FillRect draws a filled rectangle at (x, y) with dimensions width × height.

func (*DocumentBuilder) FillRectWithState

func (b *DocumentBuilder) FillRectWithState(pageIndex int, x, y, width, height float64, fill Color, state GraphicsState) *DocumentBuilder

FillRectWithState draws a filled rectangle with the given graphics state.

func (*DocumentBuilder) FillRoundedRect

func (b *DocumentBuilder) FillRoundedRect(pageIndex int, x, y, width, height, radius float64, fill Color) *DocumentBuilder

FillRoundedRect fills a rectangle with rounded corners.

func (*DocumentBuilder) FillRoundedRectWithState

func (b *DocumentBuilder) FillRoundedRectWithState(pageIndex int, x, y, width, height, radius float64, fill Color, state GraphicsState) *DocumentBuilder

FillRoundedRectWithState draws a filled rounded rectangle with graphics state.

func (*DocumentBuilder) FillStrokeCircle

func (b *DocumentBuilder) FillStrokeCircle(pageIndex int, cx, cy, radius float64, fill Color, stroke LineStyle) *DocumentBuilder

FillStrokeCircle draws a filled and stroked circle centered at (cx, cy) with the given radius.

func (*DocumentBuilder) FillStrokeCircleWithState

func (b *DocumentBuilder) FillStrokeCircleWithState(pageIndex int, cx, cy, radius float64, fill Color, stroke LineStyle, state GraphicsState) *DocumentBuilder

FillStrokeCircleWithState draws a filled and stroked circle with the given graphics state.

func (*DocumentBuilder) FillStrokeEllipse

func (b *DocumentBuilder) FillStrokeEllipse(pageIndex int, cx, cy, rx, ry float64, fill Color, stroke LineStyle) *DocumentBuilder

FillStrokeEllipse fills and strokes an axis-aligned ellipse centered at (cx, cy) with semi-axes rx and ry.

func (*DocumentBuilder) FillStrokeEllipseWithState

func (b *DocumentBuilder) FillStrokeEllipseWithState(pageIndex int, cx, cy, rx, ry float64, fill Color, stroke LineStyle, state GraphicsState) *DocumentBuilder

FillStrokeEllipseWithState draws a filled and stroked ellipse with graphics state.

func (*DocumentBuilder) FillStrokePolygon

func (b *DocumentBuilder) FillStrokePolygon(pageIndex int, points []float64, fill Color, stroke LineStyle) *DocumentBuilder

FillStrokePolygon fills and strokes a closed polygon defined by a list of (x,y) point pairs.

func (*DocumentBuilder) FillStrokePolygonWithState

func (b *DocumentBuilder) FillStrokePolygonWithState(pageIndex int, points []float64, fill Color, stroke LineStyle, state GraphicsState) *DocumentBuilder

FillStrokePolygonWithState draws a filled and stroked polygon with graphics state.

func (*DocumentBuilder) FillStrokeRect

func (b *DocumentBuilder) FillStrokeRect(pageIndex int, x, y, width, height float64, fill Color, stroke LineStyle) *DocumentBuilder

FillStrokeRect draws a filled and stroked rectangle at (x, y) with dimensions width × height.

func (*DocumentBuilder) FillStrokeRectWithState

func (b *DocumentBuilder) FillStrokeRectWithState(pageIndex int, x, y, width, height float64, fill Color, stroke LineStyle, state GraphicsState) *DocumentBuilder

FillStrokeRectWithState draws a filled and stroked rectangle with the given graphics state.

func (*DocumentBuilder) FillStrokeRoundedRect

func (b *DocumentBuilder) FillStrokeRoundedRect(pageIndex int, x, y, width, height, radius float64, fill Color, stroke LineStyle) *DocumentBuilder

FillStrokeRoundedRect fills and strokes a rectangle with rounded corners.

func (*DocumentBuilder) FillStrokeRoundedRectWithState

func (b *DocumentBuilder) FillStrokeRoundedRectWithState(pageIndex int, x, y, width, height, radius float64, fill Color, stroke LineStyle, state GraphicsState) *DocumentBuilder

FillStrokeRoundedRectWithState draws a filled and stroked rounded rectangle with graphics state.

func (*DocumentBuilder) Flow

func (b *DocumentBuilder) Flow(opts FlowOptions) *FlowBuilder

Flow starts a flowing layout region on the current page.

func (*DocumentBuilder) Folio

func (b *DocumentBuilder) Folio() *DocumentBuilder

Folio sets the page size to Folio (8.5 x 13 in).

func (*DocumentBuilder) FontByName

func (b *DocumentBuilder) FontByName(name string) font.Font

func (*DocumentBuilder) GetDefaultPageSize

func (b *DocumentBuilder) GetDefaultPageSize() (float64, float64)

GetDefaultPageSize returns the current default page size for new pages.

func (*DocumentBuilder) IsTagged

func (b *DocumentBuilder) IsTagged() bool

func (*DocumentBuilder) Keywords

func (b *DocumentBuilder) Keywords(s string) *DocumentBuilder

Keywords sets the document keywords (Info /Keywords).

func (*DocumentBuilder) Landscape

func (b *DocumentBuilder) Landscape() *DocumentBuilder

Landscape sets the current page size to landscape orientation.

func (*DocumentBuilder) Ledger

func (b *DocumentBuilder) Ledger() *DocumentBuilder

Ledger sets the page size to Ledger (17 x 11 in).

func (*DocumentBuilder) Legal

func (b *DocumentBuilder) Legal() *DocumentBuilder

Legal sets the page size to Legal (8.5 x 14 in).

func (*DocumentBuilder) Letter

func (b *DocumentBuilder) Letter() *DocumentBuilder

Letter sets the page size to Letter (8.5 x 11 in).

func (*DocumentBuilder) MarkTagged

func (b *DocumentBuilder) MarkTagged()

func (*DocumentBuilder) Metadata

func (b *DocumentBuilder) Metadata(xmp []byte) *DocumentBuilder

Metadata sets the XMP metadata stream for Catalog /Metadata (raw XML bytes).

func (*DocumentBuilder) NextMCID

func (b *DocumentBuilder) NextMCID(pageIndex int) int

func (*DocumentBuilder) NoCompressContent

func (b *DocumentBuilder) NoCompressContent() *DocumentBuilder

NoCompressContent disables FlateDecode compression of page content streams.

func (*DocumentBuilder) Note

func (b *DocumentBuilder) Note() *DocumentBuilder

Note sets the page size to Note (8.5 x 11 in).

func (*DocumentBuilder) PageAt

func (b *DocumentBuilder) PageAt(pageIndex int) *builder.Page

func (*DocumentBuilder) PageCount

func (b *DocumentBuilder) PageCount() int

func (*DocumentBuilder) PageHeight

func (b *DocumentBuilder) PageHeight(pageIndex int) float64

func (*DocumentBuilder) PageSize

func (b *DocumentBuilder) PageSize(width, height float64) *DocumentBuilder

PageSize sets the default page size in points (width, height). Default is 595 x 842 (A4).

func (*DocumentBuilder) PageWidth

func (b *DocumentBuilder) PageWidth(pageIndex int) float64

func (*DocumentBuilder) Portrait

func (b *DocumentBuilder) Portrait() *DocumentBuilder

Portrait sets the current page size to portrait orientation.

func (*DocumentBuilder) Producer

func (b *DocumentBuilder) Producer(s string) *DocumentBuilder

Producer sets the application that produced the PDF (Info /Producer).

func (*DocumentBuilder) Quarto

func (b *DocumentBuilder) Quarto() *DocumentBuilder

Quarto sets the page size to Quarto (215 x 275 mm).

func (*DocumentBuilder) RecordBlock

func (b *DocumentBuilder) RecordBlock(pageIndex int, mcid int, role string) int

func (*DocumentBuilder) RecordFigure

func (b *DocumentBuilder) RecordFigure(pageIndex int, mcid int, alt string) int

func (*DocumentBuilder) RecordList

func (b *DocumentBuilder) RecordList(pageIndex int, ordered bool, mcids []int) int

func (*DocumentBuilder) RecordSectionBlock

func (b *DocumentBuilder) RecordSectionBlock(idx int)

func (*DocumentBuilder) RecordSectionFigure

func (b *DocumentBuilder) RecordSectionFigure(idx int)

func (*DocumentBuilder) RecordSectionList

func (b *DocumentBuilder) RecordSectionList(idx int)

func (*DocumentBuilder) RecordSectionTable

func (b *DocumentBuilder) RecordSectionTable(idx int)

func (*DocumentBuilder) RegisterFallbackFont

func (b *DocumentBuilder) RegisterFallbackFont(f font.Font) *DocumentBuilder

RegisterFallbackFont registers a font to be used when the primary font lacks a glyph.

func (*DocumentBuilder) RegisterFont

func (b *DocumentBuilder) RegisterFont(f font.Font) *DocumentBuilder

RegisterFont registers a parsed font for accurate text measurement and optional embedding.

func (*DocumentBuilder) SetAcroForm

func (b *DocumentBuilder) SetAcroForm() *DocumentBuilder

SetAcroForm ensures the document has an AcroForm dictionary.

func (*DocumentBuilder) SetAcroFormSigFlags

func (b *DocumentBuilder) SetAcroFormSigFlags(flags int) *DocumentBuilder

SetAcroFormSigFlags sets /SigFlags on the AcroForm dictionary.

func (*DocumentBuilder) SetDefaultICCProfile

func (b *DocumentBuilder) SetDefaultICCProfile(profile ICCProfile) *DocumentBuilder

SetDefaultICCProfile sets an ICC color profile for the document.

func (*DocumentBuilder) SetDefaultStyle

func (b *DocumentBuilder) SetDefaultStyle(s TextStyle) *DocumentBuilder

SetDefaultStyle sets the default text style for the document.

func (*DocumentBuilder) SetLanguage

func (b *DocumentBuilder) SetLanguage(lang string) *DocumentBuilder

SetLanguage sets the default document language (Catalog /Lang), e.g. "en-US".

func (*DocumentBuilder) SetTagged

func (b *DocumentBuilder) SetTagged() *DocumentBuilder

SetTagged marks the document as tagged PDF.

func (*DocumentBuilder) Statement

func (b *DocumentBuilder) Statement() *DocumentBuilder

Statement sets the page size to Statement (5.5 x 8.5 in).

func (*DocumentBuilder) Subject

func (b *DocumentBuilder) Subject(s string) *DocumentBuilder

Subject sets the document subject (Info /Subject).

func (*DocumentBuilder) Table

func (b *DocumentBuilder) Table(cols int) ITableBuilder

Table starts a new table with the given number of columns.

func (*DocumentBuilder) TableAt

func (b *DocumentBuilder) TableAt(tableIndex int) bool

func (*DocumentBuilder) Tabloid

func (b *DocumentBuilder) Tabloid() *DocumentBuilder

Tabloid sets the page size to Tabloid (11 x 17 in).

func (*DocumentBuilder) Title

func (b *DocumentBuilder) Title(s string) *DocumentBuilder

Title sets the document title (Info /Title).

func (*DocumentBuilder) ValidPageIndex

func (b *DocumentBuilder) ValidPageIndex(idx int) bool

func (*DocumentBuilder) Warnings

func (b *DocumentBuilder) Warnings() []string

Warnings returns all font-related warnings collected during the document building.

type FloatingImage

type FloatingImage struct {
	X, Y          float64
	Width, Height float64
	Margin        float64
	Wrap          style.ImageWrap
}

FloatingImage represents an image that text should wrap around.

type FlowBuilder

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

FlowBuilder provides a high-level API for automatic content flow and relative positioning.

func (*FlowBuilder) Align

func (f *FlowBuilder) Align(a TextAlignment) *FlowBuilder

Align sets the text alignment for subsequent paragraphs in the flow.

func (*FlowBuilder) Bottom

func (f *FlowBuilder) Bottom() float64

func (*FlowBuilder) Color

func (f *FlowBuilder) Color(c Color) *FlowBuilder

Color sets the text color for subsequent elements in the flow.

func (*FlowBuilder) End

func (f *FlowBuilder) End() *DocumentBuilder

End returns the underlying DocumentBuilder.

func (*FlowBuilder) Font

func (f *FlowBuilder) Font(name string) *FlowBuilder

Font sets the font for subsequent elements in the flow.

func (*FlowBuilder) Heading

func (f *FlowBuilder) Heading(text string, level int) *FlowBuilder

Heading adds a heading to the flow.

func (*FlowBuilder) Image

func (f *FlowBuilder) Image(data []byte, w, h float64) *FlowBuilder

Image adds an image to the flow.

func (*FlowBuilder) ImageWithLayout

func (f *FlowBuilder) ImageWithLayout(imgData []byte, layout style.ImageLayout, s style.ImageStyle) *FlowBuilder

ImageWithLayout adds an image to the flow with the given layout and style.

func (*FlowBuilder) Left

func (f *FlowBuilder) Left() float64

func (*FlowBuilder) Line

func (f *FlowBuilder) Line(width float64, c Color) *FlowBuilder

Line adds a horizontal line across the flow.

func (*FlowBuilder) List

func (f *FlowBuilder) List(items []string, ordered bool) *FlowBuilder

List adds a list of items to the flow.

func (*FlowBuilder) Paragraph

func (f *FlowBuilder) Paragraph(text string) *FlowBuilder

Paragraph adds a wrapping paragraph to the flow.

func (*FlowBuilder) Rect

func (f *FlowBuilder) Rect(h float64, style LineStyle, fill Color, hasFill bool) *FlowBuilder

Rect adds a rectangle to the flow.

func (*FlowBuilder) Right

func (f *FlowBuilder) Right() float64

func (*FlowBuilder) Size

func (f *FlowBuilder) Size(size float64) *FlowBuilder

Size sets the font size for subsequent elements in the flow.

func (*FlowBuilder) Space

func (f *FlowBuilder) Space(h float64) *FlowBuilder

Space adds vertical space to the flow.

func (*FlowBuilder) Table

func (f *FlowBuilder) Table(cols int) ITableBuilder

Table starts a table in the flow.

func (*FlowBuilder) Width

func (f *FlowBuilder) Width() float64

type FlowOptions

type FlowOptions struct {
	Margin float64
	Top    float64
	Bottom float64
	Left   float64
	Right  float64
}

FlowOptions configures the layout of a flowing content area.

type FormBuilder

type FormBuilder interface {
	SetAcroForm() *DocumentBuilder
	SetAcroFormSigFlags(flags int) *DocumentBuilder
	AddTextField(pageIndex int, llx, lly, urx, ury float64, name, value, tooltip string, required bool) *DocumentBuilder
	AddCheckBox(pageIndex int, llx, lly, urx, ury float64, name string, checked bool, tooltip string, required bool) *DocumentBuilder
	AddRadioButton(pageIndex int, llx, lly, urx, ury float64, groupName, value string, checked bool, tooltip string) *DocumentBuilder
	AddSubmitButton(pageIndex int, llx, lly, urx, ury float64, name, label, submitURL, tooltip string) *DocumentBuilder
}

FormBuilder configures AcroForm and creates fields/widgets.

type GraphicsState

type GraphicsState = style.GraphicsState

type HeadingObject

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

HeadingObject handles fluent heading drawing.

func (*HeadingObject) At

func (o *HeadingObject) At(x, y float64) *HeadingObject

At sets the position for the heading.

func (*HeadingObject) Draw

func (o *HeadingObject) Draw() *Page

Draw renders the heading to the page.

type ICCProfile

type ICCProfile = style.ICCProfile

type ITableBuilder

type ITableBuilder interface {
	WithHeaderFillColor(c Color) ITableBuilder
	WithAlternateRowColor(c Color) ITableBuilder
	WithMargins(top, bottom float64) ITableBuilder
	WithColumnWidths(widths ...float64) ITableBuilder
	WithFlow(f *FlowBuilder) ITableBuilder
	AllowPageBreak() ITableBuilder
	HeaderSpec(cells ...TableCellSpec) ITableBuilder
	RowSpec(cells ...TableCellSpec) ITableBuilder
	FooterRow(cells ...TableCellSpec) ITableBuilder
	EndTable() *DocumentBuilder
	Done() *FlowBuilder
	CurrentY() float64

	// New improved methods
	At(x, y float64) ITableBuilder
	Width(w float64) ITableBuilder
	Header(texts ...string) ITableBuilder
	Row(texts ...string) ITableBuilder
	Draw() *DocumentBuilder
}

ITableBuilder describes the fluent API for building tagged tables.

type ImageBuilder

type ImageBuilder interface {
	DrawImage(x, y, widthPt, heightPt float64, raw []byte, widthPx, heightPx, bitsPerComponent int, colorSpace string) *DocumentBuilder
	DrawJPEG(x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string) *DocumentBuilder
	DrawPNG(x, y, widthPt, heightPt float64, pngData []byte) *DocumentBuilder
}

ImageBuilder covers image placement on pages.

type ImageObject

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

ImageObject handles fluent image drawing.

func (*ImageObject) At

func (o *ImageObject) At(x, y float64) *ImageObject

At sets the position for the image.

func (*ImageObject) ColorSpace

func (o *ImageObject) ColorSpace(cs string) *ImageObject

ColorSpace sets the color space of the image (e.g., "DeviceRGB").

func (*ImageObject) Draw

func (o *ImageObject) Draw() *Page

Draw renders the image to the page.

func (*ImageObject) Px

func (o *ImageObject) Px(w, h int) *ImageObject

Px sets the pixel dimensions of the image. Required for raw RGB data.

type ImageOptions

type ImageOptions = imgpkg.Options

ImageOptions is a type alias for image.Options.

type ImageReader

type ImageReader interface {
	ReadImages() ([]reader.ImageInfo, error)
	ReadImagesPerPage() ([][]reader.ImageInfo, error)
}

ImageReader extracts image metadata and raw bytes from a PDF document.

type LayerBuilder

type LayerBuilder interface {
	BeginLayer(name string, onByDefault bool) *layer.Handle
	DrawInLayer(lh *layer.Handle, pageIndex int, draw func(db *DocumentBuilder)) *DocumentBuilder
}

LayerBuilder controls optional content groups (layers).

type LayoutReader

type LayoutReader interface {
	ReadLayout() ([]reader.PageLayout, error)
	ReadTables() ([][]reader.Table, error)
}

LayoutReader extracts positioned text blocks and detects tables from page content.

type LineCap

type LineCap = style.LineCap

type LineJoin

type LineJoin = style.LineJoin

type LineObject

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

LineObject handles fluent line drawing.

func (*LineObject) Color

func (o *LineObject) Color(c Color) *LineObject

Color sets the line color.

func (*LineObject) Draw

func (o *LineObject) Draw() *Page

Draw renders the line to the page.

func (*LineObject) Style

func (o *LineObject) Style(s LineStyle) *LineObject

Style sets the line style.

func (*LineObject) Width

func (o *LineObject) Width(w float64) *LineObject

Width sets the line width.

type LineStyle

type LineStyle = style.LineStyle

type ListObject

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

ListObject handles fluent list drawing.

func (*ListObject) At

func (o *ListObject) At(x, y float64) *ListObject

func (*ListObject) Color

func (o *ListObject) Color(c Color) *ListObject

func (*ListObject) CustomMarker

func (o *ListObject) CustomMarker(s string) *ListObject

func (*ListObject) Draw

func (o *ListObject) Draw() *Page

func (*ListObject) Font

func (o *ListObject) Font(name string) *ListObject

func (*ListObject) Indent

func (o *ListObject) Indent(v float64) *ListObject

func (*ListObject) Level

func (o *ListObject) Level(l int) *ListObject

func (*ListObject) LineHeight

func (o *ListObject) LineHeight(h float64) *ListObject

func (*ListObject) Marker

func (o *ListObject) Marker(m style.ListMarker) *ListObject

func (*ListObject) Ordered

func (o *ListObject) Ordered(b bool) *ListObject

func (*ListObject) Size

func (o *ListObject) Size(size float64) *ListObject

type MetadataBuilder

type MetadataBuilder interface {
	Title(s string) *DocumentBuilder
	Author(s string) *DocumentBuilder
	Subject(s string) *DocumentBuilder
	Keywords(s string) *DocumentBuilder
	Creator(s string) *DocumentBuilder
	Producer(s string) *DocumentBuilder
	Metadata(xmp []byte) *DocumentBuilder
	SetLanguage(lang string) *DocumentBuilder
}

MetadataBuilder sets document-level metadata fields.

type OutlineBuilder

type OutlineBuilder interface {
	AddOutline(title string, pageIndex int) *DocumentBuilder
	AddOutlineURL(title string, url string) *DocumentBuilder
	AddOutlineToDest(title string, destName string) *DocumentBuilder
	AddNamedDest(name string, pageIndex int) *DocumentBuilder
	AddLinkToPage(pageIndex int, llx, lly, urx, ury float64, destPageIndex int) *DocumentBuilder
	AddLinkToDest(pageIndex int, llx, lly, urx, ury float64, destName string) *DocumentBuilder
	AddLinkToURL(pageIndex int, llx, lly, urx, ury float64, url string) *DocumentBuilder
}

OutlineBuilder manages bookmarks, named destinations, and link annotations.

type Page

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

Page represents a single page in the document and provides a fluent API for drawing on it.

func (*Page) At

func (p *Page) At(x, y float64) Pt

At returns a point for positioning elements.

func (*Page) BeginSection

func (p *Page) BeginSection() *Page

BeginSection starts a logical section for tagged content on this page.

func (*Page) CurrentY

func (p *Page) CurrentY() float64

CurrentY returns the current Y position of the "flow" if any, or some default.

func (*Page) End

func (p *Page) End() *DocumentBuilder

End returns the underlying DocumentBuilder for chaining.

func (*Page) EndSection

func (p *Page) EndSection() *Page

EndSection ends the current section on this page.

func (*Page) Flow

func (p *Page) Flow(opts FlowOptions) *FlowBuilder

Flow starts a flowing layout region on this page.

func (*Page) Heading

func (p *Page) Heading(text string, level int) *HeadingObject

Heading creates a new HeadingObject for drawing tagged headings.

func (*Page) Image

func (p *Page) Image(data []byte, w, h float64) *ImageObject

Image creates a new ImageObject for drawing on this page.

func (*Page) Line

func (p *Page) Line(start, end Pt) *LineObject

Line creates a new LineObject for drawing straight lines.

func (*Page) List

func (p *Page) List(items []string) *ListObject

List creates a new ListObject for drawing bulleted or numbered lists.

func (*Page) Paragraph

func (p *Page) Paragraph(s string) *TextBoxObject

Paragraph creates a new TextBoxObject for drawing wrapped text as a paragraph.

func (*Page) Rect

func (p *Page) Rect(rect Rect) *RectObject

Rect creates a new RectObject for drawing rectangles.

func (*Page) Table

func (p *Page) Table(cols int) ITableBuilder

Table starts a table on this page with the given number of columns.

func (*Page) Text

func (p *Page) Text(s string) *TextObject

Text creates a new TextObject for drawing on this page.

func (*Page) TextBox

func (p *Page) TextBox(s string) *TextBoxObject

TextBox creates a new TextBoxObject for drawing wrapped text.

type PageBuilder

type PageBuilder interface {
	PageSize(width, height float64) *DocumentBuilder
	AddPage() *DocumentBuilder
}

PageBuilder configures page size and manages pages.

type PathBuilder

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

PathBuilder accumulates path construction operators for a single drawing on a page. Finish with Stroke, Fill, FillStroke, or EndPath to apply the path and return to the DocumentBuilder.

func (*PathBuilder) Arc

func (p *PathBuilder) Arc(cx, cy, rx, ry, startDeg, sweepDeg float64) *PathBuilder

Arc appends an elliptical arc centered at (cx, cy) with semi-axes rx and ry. startDeg is the start angle in degrees (0 = rightmost point), sweepDeg is the angular extent (positive = counter-clockwise in PDF user space). The arc is approximated with cubic Bézier curves (max 90° per segment).

func (*PathBuilder) ClosePath

func (p *PathBuilder) ClosePath() *PathBuilder

ClosePath closes the current subpath with a straight line back to its starting point.

func (*PathBuilder) CurveTo

func (p *PathBuilder) CurveTo(x1, y1, x2, y2, x3, y3 float64) *PathBuilder

CurveTo appends a cubic Bézier curve from the current point to (x3, y3) using (x1, y1) and (x2, y2) as control points.

func (*PathBuilder) EndPath

func (p *PathBuilder) EndPath() *DocumentBuilder

EndPath discards the path without painting (useful after clipping setup).

func (*PathBuilder) Fill

func (p *PathBuilder) Fill(color Color) *DocumentBuilder

Fill paints the interior of the path with the given color and returns to the DocumentBuilder.

func (*PathBuilder) FillStroke

func (p *PathBuilder) FillStroke(fill Color, stroke LineStyle) *DocumentBuilder

FillStroke paints the interior and strokes the outline of the path.

func (*PathBuilder) FillStrokeWithState

func (p *PathBuilder) FillStrokeWithState(fill Color, stroke LineStyle, state GraphicsState) *DocumentBuilder

FillStrokeWithState paints the interior and strokes the outline with the given graphics state.

func (*PathBuilder) FillWithState

func (p *PathBuilder) FillWithState(color Color, state GraphicsState) *DocumentBuilder

FillWithState paints the interior with the given color and graphics state.

func (*PathBuilder) LineTo

func (p *PathBuilder) LineTo(x, y float64) *PathBuilder

LineTo appends a straight line from the current point to (x, y).

func (*PathBuilder) MoveTo

func (p *PathBuilder) MoveTo(x, y float64) *PathBuilder

MoveTo begins a new subpath at (x, y).

func (*PathBuilder) Rect

func (p *PathBuilder) Rect(x, y, w, h float64) *PathBuilder

Rect appends a rectangle subpath at (x, y) with dimensions w × h.

func (*PathBuilder) RoundedRect

func (p *PathBuilder) RoundedRect(x, y, w, h, r float64) *PathBuilder

RoundedRect appends a closed rounded-rectangle subpath at (x,y) with size w×h and corner radius r.

func (*PathBuilder) Stroke

func (p *PathBuilder) Stroke(style LineStyle) *DocumentBuilder

Stroke paints the path with the given line style and returns to the DocumentBuilder.

func (*PathBuilder) StrokeWithState

func (p *PathBuilder) StrokeWithState(style LineStyle, state GraphicsState) *DocumentBuilder

StrokeWithState paints the path with the given line style and graphics state.

type Pt

type Pt struct {
	X, Y float64
}

Pt represents a point in 2D space.

func At

func At(x, y float64) Pt

At returns a Pt from x and y.

type Rect

type Rect struct {
	X, Y, W, H float64
}

Rect represents a rectangle in 2D space.

func R

func R(x, y, w, h float64) Rect

R returns a Rect from x, y, w, h.

type RectObject

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

RectObject handles fluent rectangle drawing.

func (*RectObject) Draw

func (o *RectObject) Draw() *Page

Draw renders the rectangle to the page.

func (*RectObject) Fill

func (o *RectObject) Fill(c Color) *RectObject

Fill sets the fill color for the rectangle.

func (*RectObject) Stroke

func (o *RectObject) Stroke(s LineStyle) *RectObject

Stroke sets the stroke style for the rectangle.

type RichText

type RichText struct {
	Segments []RichTextSegment
}

RichText represents a sequence of styled text segments.

func NewRichText

func NewRichText() *RichText

NewRichText creates a new empty RichText.

func (*RichText) Add

func (rt *RichText) Add(text string, style TextStyle) *RichText

Add adds a new styled segment to the rich text.

func (*RichText) AddSimple

func (rt *RichText) AddSimple(text string) *RichText

AddSimple adds a segment with the default font and size.

type RichTextSegment

type RichTextSegment struct {
	Text  string
	Style TextStyle
}

RichTextSegment represents a piece of text with a specific style.

type Saver

type Saver interface {
	Save(w io.Writer) error
	SaveWithPassword(w io.Writer, userPassword, ownerPassword string) error
	SaveWithAES256Password(w io.Writer, userPassword, ownerPassword string) error
	SaveLinearized(ws writer.WriteSeeker) error
}

Saver writes a PDF document in various formats and encryption modes.

type TableBuilder

type TableBuilder struct {

	// Styling options.
	HeaderFillColor      Color
	HasHeaderFillColor   bool
	AlternateRowColor    Color
	HasAlternateRowColor bool
	// contains filtered or unexported fields
}

TableBuilder builds a tagged table that can optionally span multiple pages.

func (*TableBuilder) AllowPageBreak

func (t *TableBuilder) AllowPageBreak() ITableBuilder

AllowPageBreak enables automatic page breaks when rows exceed available space.

func (*TableBuilder) At

func (t *TableBuilder) At(x, y float64) ITableBuilder

At sets the starting position of the table.

func (*TableBuilder) CurrentY

func (t *TableBuilder) CurrentY() float64

CurrentY returns the current vertical position of the table.

func (*TableBuilder) Done

func (t *TableBuilder) Done() *FlowBuilder

Done finishes the table and returns the parent FlowBuilder if available.

func (*TableBuilder) Draw

func (t *TableBuilder) Draw() *DocumentBuilder

Draw ends the table building and returns the DocumentBuilder.

func (*TableBuilder) EndTable

func (t *TableBuilder) EndTable() *DocumentBuilder

EndTable finishes the table and returns the underlying DocumentBuilder.

func (*TableBuilder) FooterRow

func (t *TableBuilder) FooterRow(cells ...TableCellSpec) ITableBuilder

FooterRow adds a footer row that repeats on continuation pages.

func (*TableBuilder) Header

func (t *TableBuilder) Header(texts ...string) ITableBuilder

Header adds a header row with simple text cells.

func (*TableBuilder) HeaderSpec

func (t *TableBuilder) HeaderSpec(cells ...TableCellSpec) ITableBuilder

HeaderSpec adds a header row to the table.

func (*TableBuilder) Row

func (t *TableBuilder) Row(texts ...string) ITableBuilder

Row adds a data row with simple text cells.

func (*TableBuilder) RowSpec

func (t *TableBuilder) RowSpec(cells ...TableCellSpec) ITableBuilder

RowSpec adds a data row to the table.

func (*TableBuilder) Width

func (t *TableBuilder) Width(w float64) ITableBuilder

Width sets the total width of the table.

func (*TableBuilder) WithAlternateRowColor

func (t *TableBuilder) WithAlternateRowColor(c Color) ITableBuilder

WithAlternateRowColor sets a background fill color applied to every other data row.

func (*TableBuilder) WithColumnWidths

func (t *TableBuilder) WithColumnWidths(widths ...float64) ITableBuilder

WithColumnWidths sets relative weights for columns.

func (*TableBuilder) WithFlow

func (t *TableBuilder) WithFlow(f *FlowBuilder) ITableBuilder

WithFlow sets the flow builder to be updated after the table is finished.

func (*TableBuilder) WithHeaderFillColor

func (t *TableBuilder) WithHeaderFillColor(c Color) ITableBuilder

WithHeaderFillColor sets a background fill color applied to all header rows.

func (*TableBuilder) WithMargins

func (t *TableBuilder) WithMargins(top, bottom float64) ITableBuilder

WithMargins sets the top and bottom margins for page breaks.

type TableBuilderAPI

type TableBuilderAPI interface {
	BeginTable(pageIndex int, x, y, width, height float64, cols int) ITableBuilder
}

TableBuilderAPI describes the fluent API for building tagged tables.

type TableCellImageSpec

type TableCellImageSpec = table.CellImageSpec

type TableCellSpec

type TableCellSpec = table.CellSpec

type TaggedContentBuilder

type TaggedContentBuilder interface {
	SetTagged() *DocumentBuilder
	BeginSection() *DocumentBuilder
	EndSection() *DocumentBuilder
	DrawTaggedCaption(pageIndex int, text string, x, y float64, fontName string, fontSize float64) *DocumentBuilder
	DrawTaggedQuote(pageIndex int, text string, x, y float64, fontName string, fontSize float64) *DocumentBuilder
	DrawTaggedCode(pageIndex int, text string, x, y float64, fontName string, fontSize float64) *DocumentBuilder
	DrawTaggedQuoteBox(pageIndex int, text string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder
	DrawTaggedCodeBlock(pageIndex int, text string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder
}

TaggedContentBuilder exposes text-oriented tagged content helpers (sections, captions, quotes, code blocks).

type TaggedImageBuilder

type TaggedImageBuilder interface {
	DrawTaggedFigure(pageIndex int, x, y, widthPt, heightPt float64, raw []byte, widthPx, heightPx, bitsPerComponent int, colorSpace string, alt string) *DocumentBuilder
	DrawTaggedJPEG(pageIndex int, x, y, widthPt, heightPt float64, jpegData []byte, widthPx, heightPx int, colorSpace string, alt string) *DocumentBuilder
	DrawTaggedPNG(pageIndex int, x, y, widthPt, heightPt float64, pngData []byte, alt string) *DocumentBuilder
}

TaggedImageBuilder exposes tagged image helpers (figures, JPEG, PNG with alt text).

type TextAlign

type TextAlign = text.Align

type TextAlignment

type TextAlignment int

TextAlignment defines horizontal alignment for text.

const (
	AlignLeft TextAlignment = iota
	AlignCenter
	AlignRight
	AlignJustify
)

type TextBoxObject

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

TextBoxObject handles fluent wrapped text drawing.

func (*TextBoxObject) Align

func (o *TextBoxObject) Align(align TextAlignment) *TextBoxObject

func (*TextBoxObject) AsCode

func (o *TextBoxObject) AsCode() *TextBoxObject

func (*TextBoxObject) AsParagraph

func (o *TextBoxObject) AsParagraph() *TextBoxObject

func (*TextBoxObject) AsQuote

func (o *TextBoxObject) AsQuote() *TextBoxObject

func (*TextBoxObject) At

func (o *TextBoxObject) At(x, y float64) *TextBoxObject

func (*TextBoxObject) Color

func (o *TextBoxObject) Color(c Color) *TextBoxObject

func (*TextBoxObject) Draw

func (o *TextBoxObject) Draw() *Page

func (*TextBoxObject) Font

func (o *TextBoxObject) Font(name string) *TextBoxObject

func (*TextBoxObject) LetterSpacing

func (o *TextBoxObject) LetterSpacing(spacing float64) *TextBoxObject

func (*TextBoxObject) LineHeight

func (o *TextBoxObject) LineHeight(h float64) *TextBoxObject

func (*TextBoxObject) Size

func (o *TextBoxObject) Size(size float64) *TextBoxObject

func (*TextBoxObject) Style

func (o *TextBoxObject) Style(s TextStyle) *TextBoxObject

func (*TextBoxObject) Width

func (o *TextBoxObject) Width(w float64) *TextBoxObject

type TextBuilder

type TextBuilder interface {
	DrawText(text string, x, y float64, fontName string, fontSize float64) *DocumentBuilder
	DrawTextBox(pageIndex int, text string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder
	DrawTaggedParagraphBox(pageIndex int, text string, x, y float64, fontName string, fontSize float64, opts TextLayoutOptions) *DocumentBuilder
	DrawParagraph(pageIndex int, text string, x, y float64, fontName string, fontSize float64) *DocumentBuilder
	DrawHeading(pageIndex int, level int, text string, x, y float64, fontName string, fontSize float64) *DocumentBuilder
	DrawList(pageIndex int, items []string, x, y, lineHeight float64, ordered bool, fontName string, fontSize float64) *DocumentBuilder
}

TextBuilder covers basic and tagged text layout on pages.

type TextLayoutOptions

type TextLayoutOptions = text.LayoutOptions

type TextObject

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

TextObject handles fluent text drawing.

func (*TextObject) Align

func (o *TextObject) Align(a TextAlignment) *TextObject

Align sets the horizontal alignment for the text.

func (*TextObject) At

func (o *TextObject) At(x, y float64) *TextObject

At sets the position for the text.

func (*TextObject) Color

func (o *TextObject) Color(c Color) *TextObject

Color sets the color for the text.

func (*TextObject) Draw

func (o *TextObject) Draw() *Page

Draw renders the text to the page.

func (*TextObject) Font

func (o *TextObject) Font(name string) *TextObject

Font sets the font for the text.

func (*TextObject) LetterSpacing

func (o *TextObject) LetterSpacing(spacing float64) *TextObject

LetterSpacing sets the character spacing for the text.

func (*TextObject) Size

func (o *TextObject) Size(size float64) *TextObject

Size sets the font size for the text.

func (*TextObject) Style

func (o *TextObject) Style(s TextStyle) *TextObject

Style sets the complete text style.

type TextStyle

type TextStyle struct {
	FontName        string
	FontSize        float64
	Color           Color
	LetterSpacing   float64 // CharSpacing in PDF terms
	WordSpacing     float64 // Additional space between words
	HorizontalScale float64 // Percent; 100 = normal, 0 = use default
	Leading         float64 // Line spacing override; 0 = use default
	Rotation        float64 // Degrees; 0 = upright
	IsVertical      bool

	SyntheticBold   bool
	SyntheticItalic bool
}

TextStyle describes the visual appearance of a text run.

func DefaultTextStyle

func DefaultTextStyle() TextStyle

DefaultTextStyle returns a default Helvetica 12pt style.

func (TextStyle) Font

func (s TextStyle) Font(name string) TextStyle

Font returns a new style with the given font name.

func (TextStyle) Size

func (s TextStyle) Size(size float64) TextStyle

Size returns a new style with the given font size.

func (TextStyle) WithColor

func (s TextStyle) WithColor(c Color) TextStyle

WithColor returns a new style with the given color.

func (TextStyle) WithHorizontalScale

func (s TextStyle) WithHorizontalScale(scale float64) TextStyle

WithHorizontalScale returns a new style with the given horizontal scale (100 = normal).

func (TextStyle) WithLeading

func (s TextStyle) WithLeading(leading float64) TextStyle

WithLeading returns a new style with the given leading (line spacing).

func (TextStyle) WithLetterSpacing

func (s TextStyle) WithLetterSpacing(spacing float64) TextStyle

WithLetterSpacing returns a new style with the given letter spacing.

func (TextStyle) WithRotation

func (s TextStyle) WithRotation(deg float64) TextStyle

WithRotation returns a new style with the given rotation in degrees.

func (TextStyle) WithWordSpacing

func (s TextStyle) WithWordSpacing(spacing float64) TextStyle

WithWordSpacing returns a new style with the given word spacing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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