Introduction

Aspose.PDF FOSS for Go is a pure-Go library for working with PDF documents. It exposes an API for creating new PDFs from scratch, opening and editing existing files, splitting documents into per-page outputs, merging multiple PDFs, and applying password-based encryption — all without any native C or C++ dependencies.

The library is available as a Go module at github.com/aspose-pdf-foss/aspose-pdf-foss-for-go and is released under the MIT license. Install it with go get github.com/aspose-pdf-foss/aspose-pdf-foss-for-go into any Go 1.24+ project.

This post covers the core capabilities: document operations, security, AcroForm filling, table layout, bookmarks, and annotations.


Key Features

Document Splitting and Merging

The Document type provides Split() to divide a PDF into per-page documents and Append() to merge an external document in-place. PageRange lets you work with a subset of pages for selective extraction or export. Metadata exposes XMP and document-info fields for reading and writing author, title, and creation date.

import pdf "github.com/aspose-pdf-foss/aspose-pdf-foss-for-go"

doc, _ := pdf.Open("report.pdf")

// Split into per-page PDFs
pages, _ := doc.Split()
for i, p := range pages {
    p.Save(fmt.Sprintf("page%03d.pdf", i+1))
}

// Merge a second PDF into doc
doc2, _ := pdf.Open("appendix.pdf")
doc.Append(doc2)
doc.Save("combined.pdf")

Password Encryption and Permissions

EncryptionOptions configures user password, owner password, and allowed operations in a single call to SetEncryption. The supported algorithms are AES-128 (the default), AES-256 (ISO 32000-2, produces PDF 2.0 output), and RC4-128 for legacy compatibility. Permissions lets you allow or deny individual operations — print, copy, accessibility — independently. OpenWithPassword opens encrypted files; RemoveEncryption strips the password before saving a plaintext copy.

doc, _ := pdf.Open("contract.pdf")
doc.SetEncryption(pdf.EncryptionOptions{
    UserPassword:  "userpass",
    OwnerPassword: "ownerpass",
    Permissions:   &pdf.Permissions{AllowPrint: true, AllowCopy: false},
})
doc.Save("contract_protected.pdf")

AcroForm Field Processing

Form provides access to all AcroForm fields in a document. Field is the base interface; type assertions give access to TextBoxField, CheckboxField, RadioButtonField, ComboBoxField, ListBoxField, and ButtonField. Set field values by field name — the viewer regenerates appearances automatically via /NeedAppearances=true on save.

doc, _ := pdf.Open("application.pdf")
text := doc.Form().Field("full_name").(*pdf.TextBoxField)
text.SetValue("Jane Doe")

check := doc.Form().Field("agree_terms").(*pdf.CheckboxField)
check.SetChecked(true)

combo := doc.Form().Field("country").(*pdf.ComboBoxField)
combo.SetSelected(0)

doc.Save("application_filled.pdf")

Table Layout

Table, Row, and Cell build structured grid layouts on PDF pages. BorderInfo configures border style per cell or for the whole table. MarginInfo sets cell padding. TextStyle controls font, size, color, and alignment via HAlign and VAlign. Image can be placed inside cells alongside text.

tbl := pdf.NewTable()
tbl.ColumnWidths = []float64{120, 80, 80}

row := tbl.AddRow()
row.AddCell().SetText("Item")
row.AddCell().SetText("Qty")
row.AddCell().SetText("Price")

page, _ := doc.Page(1)
page.AddTable(tbl)
doc.Save("invoice.pdf")

Bookmarks and Navigation

OutlineItemCollection represents a single bookmark entry. Use SetTitle, SetBold, SetColor, and SetDestination to configure it. DestinationXYZ targets an exact page coordinate; DestinationFit fits the page in the viewer. NamedDestinations registers reusable jump targets accessible by name.

doc, _ := pdf.Open("manual.pdf")
page, _ := doc.Page(1)

chapter := pdf.NewOutlineItemCollection(doc)
chapter.SetTitle("Chapter 1: Getting Started")
chapter.SetBold(true)
chapter.SetDestination(pdf.NewDestinationXYZ(page, 0, 800, 1.0))
doc.Outlines().Add(chapter)

section := pdf.NewOutlineItemCollection(doc)
section.SetTitle("Installation")
section.SetDestination(pdf.NewDestinationFit(page))
chapter.Add(section)

doc.Save("manual_with_bookmarks.pdf")

Annotations and Stamps

AnnotationCollection holds all annotations on a page. TextAnnotation adds a sticky-note comment. StampAnnotation places an approval or informational stamp using one of the predefined StampName values. HighlightAnnotation marks text regions. RedactAnnotation permanently removes sensitive content. LinkAnnotation attaches URI or page-destination actions to clickable regions.

doc, _ := pdf.Open("draft.pdf")
page, _ := doc.Page(1)

stamp := pdf.NewStampAnnotation(page, pdf.Rectangle{LLX: 100, LLY: 700, URX: 250, URY: 750})
stamp.StampName = pdf.StampNameApproved
page.Annotations().Add(stamp)

doc.Save("draft_approved.pdf")

Quick Start

Install the module:

go get github.com/aspose-pdf-foss/aspose-pdf-foss-for-go

A minimal workflow — open a PDF, encrypt it with a password, and save:

package main

import (
    "fmt"
    pdf "github.com/aspose-pdf-foss/aspose-pdf-foss-for-go"
)

func main() {
    doc, err := pdf.Open("input.pdf")
    if err != nil {
        panic(err)
    }

    doc.SetEncryption(pdf.EncryptionOptions{
        UserPassword:  "secret",
        OwnerPassword: "ownerSecret",
        Permissions:   &pdf.Permissions{AllowPrint: true},
    })

    if err := doc.Save("output_encrypted.pdf"); err != nil {
        panic(err)
    }
    fmt.Println("Saved output_encrypted.pdf")
}

Open Source and Licensing

Aspose.PDF FOSS for Go is released under the MIT license. There are no usage restrictions, no runtime fees, and no registration requirements. The source code is available at github.com/aspose-pdf-foss/aspose-pdf-foss-for-go.

Commercial use is permitted under the MIT license terms. If your project requires enterprise-grade support, extended format coverage, or cloud integration, the Aspose.PDF enterprise product is a separate commercial offering.


Getting Started