Quick Start
Quick Start
This page shows the minimal code to open a PDF, inspect its pages, and perform
split and merge operations using Document.
Prerequisites
Before running the examples, complete Installation.
Open and Inspect a PDF
pdf.Open opens an existing file and returns a *Document. Call PageCount to
read the number of pages.
package main
import (
"fmt"
pdf "github.com/aspose-pdf-foss/aspose-pdf-foss-for-go"
)
func main() {
doc, err := pdf.Open("sample.pdf")
if err != nil {
panic(err)
}
fmt.Printf("Loaded PDF with %d pages\n", doc.PageCount())
}Split Into Per-Page Files
Document.Split divides the document into one *Document per page.
doc, _ := pdf.Open("report.pdf")
pages, _ := doc.Split()
for i, p := range pages {
p.Save(fmt.Sprintf("page_%03d.pdf", i+1))
}
fmt.Printf("Split into %d pages\n", len(pages))Merge Multiple PDFs
Document.Append appends all pages from a second document in-place.
base, _ := pdf.Open("part1.pdf")
part2, _ := pdf.Open("part2.pdf")
base.Append(part2)
base.Save("merged.pdf")Create a New Document
pdf.NewDocument creates a blank *Document. AddBlankPageFromFormat appends a page with a standard size.
doc := pdf.NewDocument()
doc.AddBlankPageFromFormat(pdf.PageFormatA4)
doc.Save("blank.pdf")Next Steps
- Developer Guide — encryption, forms, tables, bookmarks, annotations
- API Reference — full class and function listing
- KB Articles — how-to guides for specific tasks