PDF Library Features

PDF Library Features

This page summarises the major feature areas in Aspose.PDF FOSS for Go. Each section links to dedicated developer-guide pages with complete code examples.


Document Management

Document is the central type. It supports opening (Open, OpenWithPassword), creating (NewDocument), saving (Save), and operating on page collections (Split, Append, Extract, PageCount). SetMetadata and Metadata provide read/write access to Info dictionary fields.

doc, _ := pdf.Open("input.pdf")
pages, _ := doc.Split()
fmt.Printf("Split into %d pages\n", len(pages))

Security and Encryption

EncryptionOptions configures password-based encryption in a single call to Document.SetEncryption. Supported algorithms: AES-128 (default), AES-256 (ISO 32000-2 / PDF 2.0), and RC4-128. Permissions controls individual operations — print, copy, accessibility — independently.

doc, _ := pdf.Open("doc.pdf")
doc.SetEncryption(pdf.EncryptionOptions{
	UserPassword:  "user",
	OwnerPassword: "owner",
	Permissions:   &pdf.Permissions{AllowPrint: true},
})
doc.Save("doc_secured.pdf")

AcroForm Processing

Document.Form returns a *Form providing access to all fields. Type assertions expose the specific field types: TextBoxField, CheckboxField, RadioButtonField, ComboBoxField, ListBoxField, and ButtonField. Field values are written; appearances are regenerated automatically by PDF viewers.

doc, _ := pdf.Open("form.pdf")
text := doc.Form().Field("name").(*pdf.TextBoxField)
text.SetValue("Jane Doe")
doc.Save("form_filled.pdf")

Table Layout

Table, Row, and Cell build grid layouts positioned on pages. BorderInfo sets border styles per cell or for the whole table. MarginInfo sets padding. TextStyle, Font, Color, HAlign, and VAlign control text presentation.


Bookmarks and Navigation

OutlineItemCollection represents a single bookmark. Configure title, bold/italic style, link color, and destination (DestinationXYZ, DestinationFit, DestinationFitH). Nested bookmarks build a chapter/section hierarchy. NamedDestinations provides reusable page targets accessible by name.


Annotations

AnnotationCollection holds all annotations on a page. Available types include TextAnnotation, FreeTextAnnotation, StampAnnotation, HighlightAnnotation, LinkAnnotation, RedactAnnotation, InkAnnotation, LineAnnotation, SquareAnnotation, and CircleAnnotation.


Image Handling

Image represents an embedded image resource. ImageInfo exposes dimensions and color space. Images can be added to pages directly or embedded in table cells. OptimizeImageOptions provides compression parameters for file size reduction.


Rendering to Image

BmpDevice, PngDevice, JpegDevice, GifDevice, and TiffDevice render individual PDF pages to raster images. Each device is constructed with a Resolution value and exposes a Render* method that writes the output to an io.Writer. RenderOptions controls rendering parameters — output resolution (DPI) and background colour.

doc, _ := pdf.Open("report.pdf")
page, _ := doc.Page(1)
dev := pdf.NewPngDevice(pdf.Resolution{DPI: 150})
f, _ := os.Create("page1.png")
defer f.Close()
dev.Process(page, f)

Text Search

SearchText accepts a query string and SearchOptions and returns a slice of TextMatch results. Each TextMatch exposes the matched text, its bounding box on the page, and the page index where it was found.

doc, _ := pdf.Open("report.pdf")
matches, _ := doc.SearchText("invoice", pdf.SearchOptions{CaseInsensitive: true})
for _, m := range matches {
	fmt.Printf("Found %q on page %d\n", m.Text, m.PageNumber)
}

Form Flattening

Document.Flatten converts all interactive form fields to static content. Field values are baked into the page graphics and the form fields are removed, producing a PDF that cannot be edited.

doc, _ := pdf.Open("form_filled.pdf")
doc.Flatten()
doc.Save("form_flat.pdf")

API Reference Summary

TypePurpose
DocumentCore document container — open, create, save, split, merge
PageSingle page access — size, annotations, content
FormAcroForm container — field enumeration and access
TableGrid layout element
EncryptionOptionsPassword and algorithm configuration
PermissionsPer-operation access control flags
OutlineItemCollectionBookmark tree node
AnnotationCollectionPage annotation container
MetadataInfo dictionary read/write
ImageEmbedded image resource
BmpDeviceRender PDF page to BMP
PngDeviceRender PDF page to PNG
JpegDeviceRender PDF page to JPEG
TiffDeviceRender PDF page to TIFF
GifDeviceRender PDF page to GIF
RenderOptionsRender parameters — DPI and background colour
SearchOptionsText search configuration
TextMatchSingle text search result with bounding box
LinearGradientLinear gradient fill for vector shapes
RadialGradientRadial gradient fill for vector shapes

See Also

 English