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.NewDocumentFromFormat creates a blank *Document with the given page format.

doc := pdf.NewDocumentFromFormat(pdf.PageFormatA4)
doc.Save("blank.pdf")

Next Steps

See Also

 English