Documentation
¶
Overview ¶
Package document provides the top-level API for creating and writing PDF documents.
Index ¶
- Variables
- type Annotation
- type DestType
- type Destination
- type Document
- func (d *Document) Add(e layout.Element)
- func (d *Document) AddAbsolute(e layout.Element, x, y, width float64)
- func (d *Document) AddAbsoluteOnPage(e layout.Element, x, y, width float64, pageIndex int)
- func (d *Document) AddAbsoluteRight(e layout.Element, rightOffset, y, width float64)
- func (d *Document) AddAbsoluteWithOpts(e layout.Element, x, y, width float64, opts layout.AbsoluteOpts)
- func (d *Document) AddHTML(htmlStr string, opts *foliohtml.Options) error
- func (d *Document) AddNamedDest(dest NamedDest)
- func (d *Document) AddOutline(title string, dest Destination) *Outline
- func (d *Document) AddPage() *Page
- func (d *Document) Page(index int) *Page
- func (d *Document) PageCount() int
- func (d *Document) RemovePage(index int) error
- func (d *Document) Save(path string) error
- func (d *Document) SetAcroForm(form interface{ ... })
- func (d *Document) SetAutoBookmarks(enabled bool)
- func (d *Document) SetEncryption(cfg EncryptionConfig)
- func (d *Document) SetFirstMarginBoxes(boxes map[string]layout.MarginBox)
- func (d *Document) SetFirstMargins(m layout.Margins)
- func (d *Document) SetFooter(fn PageDecorator)
- func (d *Document) SetHeader(fn PageDecorator)
- func (d *Document) SetLeftMargins(m layout.Margins)
- func (d *Document) SetMarginBoxes(boxes map[string]layout.MarginBox)
- func (d *Document) SetMargins(m layout.Margins)
- func (d *Document) SetPageLabels(ranges ...PageLabelRange)
- func (d *Document) SetPdfA(config PdfAConfig)
- func (d *Document) SetRightMargins(m layout.Margins)
- func (d *Document) SetTagged(enabled bool)
- func (d *Document) SetViewerPreferences(vp ViewerPreferences)
- func (d *Document) SetWatermark(text string)
- func (d *Document) SetWatermarkConfig(cfg WatermarkConfig)
- func (d *Document) WriteTo(w io.Writer) (int64, error)
- type EncryptionAlgorithm
- type EncryptionConfig
- type IndirectObject
- type Info
- type LabelStyle
- type MarkupType
- type NamedDest
- type Outline
- type Page
- func (p *Page) AddHighlight(rect [4]float64, color [3]float64, quadPoints [][8]float64)
- func (p *Page) AddImage(img *folioimage.Image, x, y, width, height float64)
- func (p *Page) AddInternalLink(rect [4]float64, destName string)
- func (p *Page) AddLink(rect [4]float64, uri string)
- func (p *Page) AddPageLink(rect [4]float64, pageIndex int)
- func (p *Page) AddSquiggly(rect [4]float64, color [3]float64, quadPoints [][8]float64)
- func (p *Page) AddStrikeOut(rect [4]float64, color [3]float64, quadPoints [][8]float64)
- func (p *Page) AddText(text string, f *font.Standard, size, x, y float64)
- func (p *Page) AddTextAnnotation(rect [4]float64, text, icon string)
- func (p *Page) AddTextAnnotationOpen(rect [4]float64, text, icon string)
- func (p *Page) AddTextEmbedded(text string, ef *font.EmbeddedFont, size, x, y float64)
- func (p *Page) AddTextMarkup(markupType MarkupType, rect [4]float64, color [3]float64, ...)
- func (p *Page) AddUnderline(rect [4]float64, color [3]float64, quadPoints [][8]float64)
- func (p *Page) ContentStream() *content.Stream
- func (p *Page) SetArtBox(rect [4]float64) *Page
- func (p *Page) SetBleedBox(rect [4]float64) *Page
- func (p *Page) SetCropBox(rect [4]float64) *Page
- func (p *Page) SetOpacity(alpha float64) string
- func (p *Page) SetOpacityFillStroke(fillAlpha, strokeAlpha float64) string
- func (p *Page) SetRotate(degrees int)
- func (p *Page) SetSize(ps PageSize) *Page
- func (p *Page) SetTrimBox(rect [4]float64) *Page
- type PageContext
- type PageDecorator
- type PageLabelRange
- type PageLayout
- type PageMode
- type PageSize
- type PdfAConfig
- type PdfALevel
- type StructTag
- type ViewerPreferences
- type WatermarkConfig
- type Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ISO A series PageSizeA0 = PageSize{Width: 2383.94, Height: 3370.39} PageSizeA1 = PageSize{Width: 1683.78, Height: 2383.94} PageSizeA2 = PageSize{Width: 1190.55, Height: 1683.78} PageSizeA3 = PageSize{Width: 841.89, Height: 1190.55} PageSizeA4 = PageSize{Width: 595.28, Height: 841.89} PageSizeA5 = PageSize{Width: 419.53, Height: 595.28} PageSizeA6 = PageSize{Width: 297.64, Height: 419.53} // ISO B series PageSizeB4 = PageSize{Width: 708.66, Height: 1000.63} PageSizeB5 = PageSize{Width: 498.90, Height: 708.66} // North American sizes PageSizeLetter = PageSize{Width: 612, Height: 792} PageSizeLegal = PageSize{Width: 612, Height: 1008} PageSizeTabloid = PageSize{Width: 792, Height: 1224} PageSizeLedger = PageSize{Width: 1224, Height: 792} PageSizeExecutive = PageSize{Width: 522, Height: 756} )
Standard page sizes (dimensions in PDF points, 1 point = 1/72 inch).
Functions ¶
This section is empty.
Types ¶
type Annotation ¶
type Annotation struct {
// contains filtered or unexported fields
}
Annotation represents a PDF annotation on a page.
type DestType ¶
type DestType int
DestType is the type of PDF destination.
const ( // DestFit displays the page with its contents magnified just enough // to fit the entire page within the window (ISO 32000 §12.3.2.2). DestFit DestType = iota // DestXYZ positions the page at (left, top) with the given zoom. // Zero values mean "keep current" (ISO 32000 §12.3.2.2). DestXYZ )
type Destination ¶
type Destination struct {
PageIndex int // zero-based page index
Type DestType
Left float64 // for XYZ: left coordinate (0 = use current)
Top float64 // for XYZ: top coordinate (0 = use current)
Zoom float64 // for XYZ: zoom factor (0 = use current)
}
Destination describes where a bookmark links to.
func FitDest ¶
func FitDest(pageIndex int) Destination
FitDest creates a Fit destination for the given page index.
func XYZDest ¶
func XYZDest(pageIndex int, left, top, zoom float64) Destination
XYZDest creates an XYZ destination for the given page, position, and zoom. Pass 0 for left, top, or zoom to keep the current value.
type Document ¶
type Document struct {
Info Info // document metadata (Title, Author, etc.)
// contains filtered or unexported fields
}
Document is the top-level API for building a PDF.
Example (Simple) ¶
package main
import (
"fmt"
"os"
"github.com/carlos7ags/folio/document"
"github.com/carlos7ags/folio/font"
"github.com/carlos7ags/folio/layout"
)
func main() {
doc := document.NewDocument(document.PageSizeLetter)
doc.Info.Title = "Hello World"
doc.Info.Author = "Folio"
doc.Add(layout.NewHeading("Hello, Folio!", layout.H1))
doc.Add(layout.NewParagraph(
"This is a paragraph of text created with the Folio PDF library.",
font.Helvetica, 12,
))
if err := doc.Save("hello.pdf"); err != nil {
fmt.Println("error:", err)
return
}
_ = os.Remove("hello.pdf")
fmt.Println("Created hello.pdf")
}
Output: Created hello.pdf
Example (Table) ¶
package main
import (
"fmt"
"os"
"github.com/carlos7ags/folio/document"
"github.com/carlos7ags/folio/font"
"github.com/carlos7ags/folio/layout"
)
func main() {
doc := document.NewDocument(document.PageSizeA4)
doc.Info.Title = "Invoice"
doc.Add(layout.NewHeading("Invoice #1234", layout.H1))
tbl := layout.NewTable().SetAutoColumnWidths()
h := tbl.AddHeaderRow()
h.AddCell("Item", font.HelveticaBold, 10)
h.AddCell("Qty", font.HelveticaBold, 10)
h.AddCell("Price", font.HelveticaBold, 10)
r1 := tbl.AddRow()
r1.AddCell("Widget", font.Helvetica, 10)
r1.AddCell("5", font.Helvetica, 10)
r1.AddCell("$250.00", font.Helvetica, 10)
doc.Add(tbl)
_ = doc.Save("invoice.pdf")
_ = os.Remove("invoice.pdf")
fmt.Println("Created invoice")
}
Output: Created invoice
Example (TaggedPdfA) ¶
package main
import (
"fmt"
"os"
"github.com/carlos7ags/folio/document"
)
func main() {
doc := document.NewDocument(document.PageSizeLetter)
doc.Info.Title = "Accessible Report"
doc.Info.Author = "Folio"
doc.SetTagged(true)
doc.SetPdfA(document.PdfAConfig{Level: document.PdfA2B})
doc.AddPage() // blank page — PDF/A requires embedded fonts for text
_ = doc.Save("accessible.pdf")
_ = os.Remove("accessible.pdf")
fmt.Println("Created accessible PDF/A")
}
Output: Created accessible PDF/A
func NewDocument ¶
NewDocument creates a new PDF document with the given page size.
func (*Document) Add ¶
Add appends a layout element (e.g. Paragraph) to the document. Elements are laid out automatically with word wrapping and page breaks when WriteTo/Save is called.
func (*Document) AddAbsolute ¶
AddAbsolute places a layout element at fixed (x, y) coordinates on the last page produced by the layout engine. The element does not participate in normal vertical flow. Coordinates are in PDF points from the bottom-left. Width sets the layout width for word-wrapping; 0 uses full content width.
func (*Document) AddAbsoluteOnPage ¶
AddAbsoluteOnPage places a layout element at (x, y) on a specific layout page (0-indexed). If the page doesn't exist, the element is ignored.
func (*Document) AddAbsoluteRight ¶
AddAbsoluteRight places a layout element whose right edge is at (pageWidth - rightOffset) on the last page. The X coordinate is adjusted after layout to account for the element's actual width.
func (*Document) AddAbsoluteWithOpts ¶
func (d *Document) AddAbsoluteWithOpts(e layout.Element, x, y, width float64, opts layout.AbsoluteOpts)
AddAbsoluteWithOpts places an element with full positioning control.
func (*Document) AddHTML ¶
AddHTML parses an HTML string and adds the resulting layout elements to the document. It also extracts metadata from <title> and <meta> tags and applies them to the document's Info fields (Title, Author, Subject, Keywords, Creator). Existing non-empty Info fields are not overwritten.
If the HTML contains @page CSS rules, the page size and margins are applied to the document.
opts may be nil for default settings.
func (*Document) AddNamedDest ¶
AddNamedDest registers a named destination within the document. Named destinations can be used as targets for internal links.
func (*Document) AddOutline ¶
func (d *Document) AddOutline(title string, dest Destination) *Outline
AddOutline adds a top-level bookmark to the document.
func (*Document) Page ¶
Page returns the page at the given zero-based index. Panics if index is out of range.
func (*Document) RemovePage ¶
RemovePage removes the page at the given zero-based index. Returns an error if the index is out of range.
func (*Document) SetAcroForm ¶
func (d *Document) SetAcroForm(form interface { Build(func(core.PdfObject) *core.PdfIndirectReference, []*core.PdfIndirectReference) (*core.PdfIndirectReference, map[int][]*core.PdfIndirectReference) })
SetAcroForm attaches an interactive form to the document. The form object must implement the Build method (typically *forms.AcroForm).
func (*Document) SetAutoBookmarks ¶
SetAutoBookmarks enables automatic bookmark/outline generation from layout headings (H1-H6). When enabled, each Heading element in the document flow produces a bookmark entry. Headings are nested by level: H2 under H1, H3 under H2, etc.
func (*Document) SetEncryption ¶
func (d *Document) SetEncryption(cfg EncryptionConfig)
SetEncryption enables encryption on the document. The configuration specifies the algorithm, passwords, and permissions.
doc.SetEncryption(document.EncryptionConfig{
Algorithm: document.EncryptAES256,
UserPassword: "secret",
OwnerPassword: "admin",
Permissions: core.PermPrint | core.PermExtract,
})
func (*Document) SetFirstMarginBoxes ¶
SetFirstMarginBoxes sets margin box content for the first page only.
func (*Document) SetFirstMargins ¶
SetFirstMargins sets margins for the first page only (@page :first).
func (*Document) SetFooter ¶
func (d *Document) SetFooter(fn PageDecorator)
SetFooter sets a decorator that draws on every page (e.g. page numbers). The decorator runs after layout, so PageContext.TotalPages is accurate.
func (*Document) SetHeader ¶
func (d *Document) SetHeader(fn PageDecorator)
SetHeader sets a decorator that draws on every page (e.g. title, logo). The decorator runs after layout, so PageContext.TotalPages is accurate.
func (*Document) SetLeftMargins ¶
SetLeftMargins sets margins for left (even) pages (@page :left).
func (*Document) SetMarginBoxes ¶
SetMarginBoxes sets default margin box content for all pages.
func (*Document) SetMargins ¶
SetMargins sets the page margins used by the layout engine (in PDF points). Default is 72pt (1 inch) on all sides.
func (*Document) SetPageLabels ¶
func (d *Document) SetPageLabels(ranges ...PageLabelRange)
SetPageLabels configures page label ranges for the document. Each range applies from its PageIndex until the next range starts.
Example — front matter in Roman numerals, body in decimal:
doc.SetPageLabels(
document.PageLabelRange{PageIndex: 0, Style: document.LabelRomanLower, Start: 1},
document.PageLabelRange{PageIndex: 4, Style: document.LabelDecimal, Start: 1},
)
func (*Document) SetPdfA ¶
func (d *Document) SetPdfA(config PdfAConfig)
SetPdfA enables PDF/A conformance on the document. This enforces: font embedding, XMP metadata, output intent, and disables encryption. For level A, tagging is enabled automatically.
func (*Document) SetRightMargins ¶
SetRightMargins sets margins for right (odd) pages (@page :right).
func (*Document) SetTagged ¶
SetTagged enables tagged PDF output (PDF/UA foundation). When enabled, the document includes a structure tree with semantic tags (P, H1-H6, Table, Figure, etc.) and marked content operators in the content streams. This enables screen readers, text extraction, and accessibility compliance (Section 508, EN 301 549).
func (*Document) SetViewerPreferences ¶
func (d *Document) SetViewerPreferences(vp ViewerPreferences)
SetViewerPreferences configures how viewers display the document.
func (*Document) SetWatermark ¶
SetWatermark sets a diagonal text watermark rendered behind content on every page. Uses default styling: 60pt light gray Helvetica at 45 degrees, 0.3 opacity.
func (*Document) SetWatermarkConfig ¶
func (d *Document) SetWatermarkConfig(cfg WatermarkConfig)
SetWatermarkConfig sets a watermark with full control over styling. Zero-value fields are replaced with defaults: FontSize=60, Color=(0.85,0.85,0.85), Angle=45, Opacity=0.3.
type EncryptionAlgorithm ¶
type EncryptionAlgorithm int
EncryptionAlgorithm selects the encryption scheme.
const ( // EncryptRC4128 uses RC4 with a 128-bit key (PDF 1.4+, widely compatible). EncryptRC4128 EncryptionAlgorithm = iota // EncryptAES128 uses AES-128-CBC (PDF 1.6+, recommended minimum). EncryptAES128 // EncryptAES256 uses AES-256-CBC (PDF 2.0, strongest). EncryptAES256 )
type EncryptionConfig ¶
type EncryptionConfig struct {
Algorithm EncryptionAlgorithm
UserPassword string // password to open the document (may be empty)
OwnerPassword string // password for full access (defaults to UserPassword)
Permissions core.Permission // granted permissions when opened with user password
}
EncryptionConfig holds the settings for document encryption.
type IndirectObject ¶
IndirectObject pairs a PdfObject with its object/generation numbers for writing as an indirect object definition.
type Info ¶
type Info struct {
Title string
Author string
Subject string
Keywords string
Creator string // application that created the original content
Producer string // application that produced the PDF
CreationDate time.Time
ModDate time.Time
}
Info holds document metadata written to the PDF trailer's /Info dictionary (ISO 32000 §14.3.3).
type LabelStyle ¶
type LabelStyle string
LabelStyle specifies the numbering style for page labels.
const ( // LabelDecimal uses decimal numbering (1, 2, 3, ...). LabelDecimal LabelStyle = "D" // LabelRomanUpper uses uppercase Roman numerals (I, II, III, ...). LabelRomanUpper LabelStyle = "R" // LabelRomanLower uses lowercase Roman numerals (i, ii, iii, ...). LabelRomanLower LabelStyle = "r" // LabelAlphaUpper uses uppercase alphabetic labels (A, B, C, ...). LabelAlphaUpper LabelStyle = "A" // LabelAlphaLower uses lowercase alphabetic labels (a, b, c, ...). LabelAlphaLower LabelStyle = "a" // LabelNone disables numbering, showing only the prefix. LabelNone LabelStyle = "" )
type MarkupType ¶
type MarkupType int
MarkupType identifies the kind of text markup annotation.
const ( // MarkupHighlight represents a yellow highlight annotation. MarkupHighlight MarkupType = iota // MarkupUnderline represents a red underline annotation. MarkupUnderline // MarkupSquiggly represents a wavy underline annotation. MarkupSquiggly // MarkupStrikeOut represents a strikethrough annotation. MarkupStrikeOut )
type NamedDest ¶
type NamedDest struct {
Name string // destination name
PageIndex int // 0-based page index
// Fit type: "Fit" (fit page), "FitH" (fit width at y), "XYZ" (position + zoom)
FitType string
Top float64 // y position for FitH/XYZ
Left float64 // x position for XYZ
Zoom float64 // zoom level for XYZ (0 = unchanged)
}
NamedDest is a named destination within the document.
type Outline ¶
type Outline struct {
Title string
Dest Destination
Children []Outline
}
Outline represents a bookmark entry in the PDF outline tree. Outlines can be nested (children form sub-bookmarks).
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page represents a single page in a document. It tracks font resources, image resources, and content stream operations.
func (*Page) AddHighlight ¶
AddHighlight adds a highlight annotation over a text region. rect defines the bounding box. color is [R, G, B] in [0, 1] (e.g. [1, 1, 0] for yellow). quadPoints defines the exact text regions as quadrilaterals — each quad is 8 floats: [x1,y1, x2,y2, x3,y3, x4,y4] (bottom-left origin, counterclockwise). If quadPoints is nil, a single quad matching rect is used.
func (*Page) AddImage ¶
func (p *Page) AddImage(img *folioimage.Image, x, y, width, height float64)
AddImage draws an image at (x, y) with the given width and height in PDF points. If width or height is 0, it is calculated from the other dimension preserving the aspect ratio. If both are 0, the image is placed at its natural size (1 pixel = 1 point). Panics if img is nil or width/height is negative.
func (*Page) AddInternalLink ¶
AddInternalLink adds a clickable link to a named destination within the document.
func (*Page) AddLink ¶
AddLink adds a clickable link annotation to the page. rect is [x1, y1, x2, y2] in PDF points (bottom-left origin). uri is the URL to open when clicked.
func (*Page) AddPageLink ¶
AddPageLink adds a clickable link to a specific page in the document (0-based index).
func (*Page) AddSquiggly ¶
AddSquiggly adds a squiggly underline annotation over a text region.
func (*Page) AddStrikeOut ¶
AddStrikeOut adds a strikeout annotation over a text region.
func (*Page) AddText ¶
AddText draws text at the given (x, y) position using a standard font. Coordinates are in PDF points with origin at bottom-left. Panics if f is nil or size is negative.
func (*Page) AddTextAnnotation ¶
AddTextAnnotation adds a sticky note (text annotation) at the given position. The note appears as an icon that reveals the text when clicked. rect is [x1, y1, x2, y2] defining the icon position. icon is one of: "Comment", "Note", "Help", "Insert", "Key", "NewParagraph", "Paragraph" (empty string defaults to "Note").
func (*Page) AddTextAnnotationOpen ¶
AddTextAnnotationOpen adds a sticky note that is initially open (popup visible).
func (*Page) AddTextEmbedded ¶
func (p *Page) AddTextEmbedded(text string, ef *font.EmbeddedFont, size, x, y float64)
AddTextEmbedded draws text at the given (x, y) position using an embedded font. The text is encoded as glyph IDs for CIDFont rendering. Panics if ef is nil or size is negative.
func (*Page) AddTextMarkup ¶
func (p *Page) AddTextMarkup(markupType MarkupType, rect [4]float64, color [3]float64, quadPoints [][8]float64)
AddTextMarkup adds a text markup annotation of the given type. This is a generic version of AddHighlight/AddUnderline/AddSquiggly/AddStrikeOut.
func (*Page) AddUnderline ¶
AddUnderline adds an underline annotation over a text region.
func (*Page) ContentStream ¶
ContentStream returns the raw content stream builder for advanced usage. Returns nil if no content has been added.
func (*Page) SetArtBox ¶
SetArtBox sets the meaningful content area of the page. Defaults to CropBox.
func (*Page) SetBleedBox ¶
SetBleedBox sets the bleed region for production (area to which page content should extend for trimming). Defaults to CropBox.
func (*Page) SetCropBox ¶
SetCropBox sets the visible region of the page. Content outside this box is clipped by the viewer. If not set, defaults to MediaBox. rect is [x1, y1, x2, y2] in PDF points.
func (*Page) SetOpacity ¶
SetOpacity sets the fill and stroke opacity for subsequent drawing operations. alpha is in [0, 1] where 0 = fully transparent and 1 = fully opaque. Returns the ExtGState resource name (e.g. "GS1") so you can also call stream.SetExtGState(name) directly.
func (*Page) SetOpacityFillStroke ¶
SetOpacityFillStroke sets separate fill and stroke opacity. fillAlpha controls non-stroke operations (text fill, shape fill). strokeAlpha controls stroke operations (outlines, borders). Values are clamped to [0, 1]. NaN is treated as 1.0 (fully opaque).
func (*Page) SetRotate ¶
SetRotate sets the page rotation in degrees. Must be a multiple of 90. Common values: 0 (default), 90 (landscape), 180 (upside down), 270. Panics if degrees is not a multiple of 90.
func (*Page) SetSize ¶
SetSize overrides the page size for this page, allowing mixed page sizes within a document (e.g., a landscape insert in a portrait document). Pass a PageSize value; use standard sizes like PageSizeA4 or PageSizeLetter, or define a custom PageSize{Width, Height}.
func (*Page) SetTrimBox ¶
SetTrimBox sets the intended finished page dimensions after trimming. Defaults to CropBox. Important for print production.
type PageContext ¶
type PageContext struct {
PageIndex int // 0-based page index
TotalPages int // total number of pages in the document
}
PageContext provides page information to header/footer decorators.
type PageDecorator ¶
type PageDecorator func(ctx PageContext, page *Page)
PageDecorator is a callback that draws content on every page. It receives the page context and a Page to draw on. Decorators run after layout, so TotalPages is accurate.
type PageLabelRange ¶
type PageLabelRange struct {
PageIndex int // 0-based page index where this range starts
Style LabelStyle // numbering style
Prefix string // prefix before the number (e.g. "A-")
Start int // starting number (default 1)
}
PageLabelRange defines a page label range starting at a given page index. All pages from PageIndex until the next range use this label style.
type PageLayout ¶
type PageLayout string
PageLayout controls how pages are displayed when the document is opened.
const ( // LayoutSinglePage displays one page at a time. LayoutSinglePage PageLayout = "SinglePage" // LayoutOneColumn displays pages in a single continuous scrolling column. LayoutOneColumn PageLayout = "OneColumn" // LayoutTwoColumnLeft displays pages in two columns with odd pages on the left. LayoutTwoColumnLeft PageLayout = "TwoColumnLeft" // LayoutTwoColumnRight displays pages in two columns with odd pages on the right. LayoutTwoColumnRight PageLayout = "TwoColumnRight" // LayoutTwoPageLeft displays two pages at a time with odd pages on the left. LayoutTwoPageLeft PageLayout = "TwoPageLeft" // LayoutTwoPageRight displays two pages at a time with odd pages on the right. LayoutTwoPageRight PageLayout = "TwoPageRight" )
type PageMode ¶
type PageMode string
PageMode controls what panel is visible when the document is opened.
const ( // ModeNone shows no panel when the document is opened (default). ModeNone PageMode = "UseNone" // ModeOutlines shows the bookmarks panel when the document is opened. ModeOutlines PageMode = "UseOutlines" // ModeThumbs shows the page thumbnails panel when the document is opened. ModeThumbs PageMode = "UseThumbs" // ModeFullScreen opens the document in full-screen mode. ModeFullScreen PageMode = "FullScreen" // ModeOC shows the optional content panel when the document is opened. ModeOC PageMode = "UseOC" // ModeAttach shows the attachments panel when the document is opened. ModeAttach PageMode = "UseAttachments" )
type PdfAConfig ¶
type PdfAConfig struct {
Level PdfALevel
// ICCProfile is the ICC color profile data for the output intent.
// If nil, a minimal sRGB profile description is used.
ICCProfile []byte
// OutputCondition is the output condition identifier
// (e.g. "sRGB IEC61966-2.1"). Defaults to "sRGB IEC61966-2.1".
OutputCondition string
}
PdfAConfig holds PDF/A conformance settings.
type PdfALevel ¶
type PdfALevel int
PdfALevel specifies the PDF/A conformance level.
const ( // PdfA2B is PDF/A-2b (ISO 19005-2:2011, Level B). // Based on PDF 1.7. Allows transparency. Requires font embedding, // XMP metadata, and an output intent with ICC profile. PdfA2B PdfALevel = iota // PdfA2U is PDF/A-2u (Level U). Adds Unicode mapping requirement. PdfA2U // PdfA2A is PDF/A-2a (Level A). Adds structure tagging requirement. PdfA2A // PdfA3B is PDF/A-3b. Like A-2b but allows file attachments. PdfA3B // PdfA1B is PDF/A-1b (ISO 19005-1:2005, Level B). // Based on PDF 1.4. Forbids transparency. Requires font embedding, // XMP metadata, and an output intent with ICC profile. PdfA1B // PdfA1A is PDF/A-1a (Level A). Like 1b but adds structure tagging. PdfA1A )
type StructTag ¶
type StructTag string
StructTag is a standard PDF structure type (ISO 32000 §14.8.4).
const ( // TagDocument is the root structure element for the entire document. TagDocument StructTag = "Document" // TagPart represents a large division of a document. TagPart StructTag = "Part" // TagSection represents a section within a document part. TagSection StructTag = "Sect" // TagH1 represents a level-1 heading. TagH1 StructTag = "H1" // TagH2 represents a level-2 heading. TagH2 StructTag = "H2" // TagH3 represents a level-3 heading. TagH3 StructTag = "H3" // TagH4 represents a level-4 heading. TagH4 StructTag = "H4" // TagH5 represents a level-5 heading. TagH5 StructTag = "H5" // TagH6 represents a level-6 heading. TagH6 StructTag = "H6" // TagP represents a paragraph. TagP StructTag = "P" // TagSpan represents an inline span of text. TagSpan StructTag = "Span" // TagTable represents a table. TagTable StructTag = "Table" // TagTR represents a table row. TagTR StructTag = "TR" // TagTH represents a table header cell. TagTH StructTag = "TH" // TagTD represents a table data cell. TagTD StructTag = "TD" // TagTHead represents a table header row group. TagTHead StructTag = "THead" // TagTBody represents a table body row group. TagTBody StructTag = "TBody" // TagL represents a list. TagL StructTag = "L" // TagLI represents a list item. TagLI StructTag = "LI" // TagLbl represents a list label (bullet or number). TagLbl StructTag = "Lbl" // TagLBody represents the body content of a list item. TagLBody StructTag = "LBody" // TagFigure represents an image or illustration. TagFigure StructTag = "Figure" // TagCaption represents a caption for a figure or table. TagCaption StructTag = "Caption" // TagLink represents a hyperlink. TagLink StructTag = "Link" // TagBlockQuote represents a block quotation. TagBlockQuote StructTag = "BlockQuote" // TagDiv represents a generic block-level grouping element. TagDiv StructTag = "Div" )
type ViewerPreferences ¶
type ViewerPreferences struct {
// How pages are arranged.
PageLayout PageLayout
// What panel is visible on open.
PageMode PageMode
// Hide viewer UI elements.
HideToolbar bool
HideMenubar bool
HideWindowUI bool
// Fit the window to the first page.
FitWindow bool
// Center the window on screen.
CenterWindow bool
// Display the document title (vs filename) in the title bar.
DisplayDocTitle bool
// Page to display on open (0-based). -1 = not set.
OpenPage int
// Zoom on open: "Fit", "FitH", "FitV", "FitB", or a percentage (e.g. 100).
// Empty string = viewer default.
OpenZoom string
}
ViewerPreferences controls how the PDF viewer displays the document.
type WatermarkConfig ¶
type WatermarkConfig struct {
Text string // the watermark text (required)
FontSize float64 // font size in points (default 60)
ColorR float64 // red component 0-1 (default 0.85)
ColorG float64 // green component 0-1 (default 0.85)
ColorB float64 // blue component 0-1 (default 0.85)
Angle float64 // rotation angle in degrees (default 45)
Opacity float64 // fill opacity 0-1 (default 0.3)
}
WatermarkConfig holds parameters for a diagonal text watermark rendered behind content on every page.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer serializes a collection of indirect objects into a valid PDF file. It handles the PDF file structure: header, object definitions, cross-reference table, trailer, and EOF marker.
func (*Writer) AddObject ¶
func (w *Writer) AddObject(obj core.PdfObject) *core.PdfIndirectReference
AddObject registers an object to be written. Returns the indirect reference that can be used to refer to this object elsewhere.
func (*Writer) SetEncryption ¶
SetEncryption configures encryption for the PDF output. The encrypt dictionary is added as an indirect object; its object number is recorded so the encryption walk skips it.
func (*Writer) SetInfo ¶
func (w *Writer) SetInfo(ref *core.PdfIndirectReference)
SetInfo sets the document info reference for the trailer /Info entry.
func (*Writer) SetRoot ¶
func (w *Writer) SetRoot(ref *core.PdfIndirectReference)
SetRoot sets the document catalog reference for the trailer /Root entry.