Skip to content

Page and pages#

A page is a simple structure:

type Page struct {
    Objnum      Objectnumber // The "/Page" object
    Annotations []Annotation
    Faces       []*Face
    Images      []*Imagefile
    Width       float64
    Height      float64
    OffsetX     float64
    OffsetY     float64
    Dict        Dict // Additional dictionary entries such as "/Trimbox"
}

Pages are split into two parts in the PDF, a dictionary and a content stream. The Objnum points to the dictionary.

A page is created and added to the PDF with

func (pw *PDF) AddPage(content *Object, page Objectnumber) *Page

When you create a page with AddPage(), you can pass pdf.Objectnumber(0) for the second argument. AddPage() creates the dictionary object itself.

You need to register all used Annotations, Faces and Images to the page object in order to get the contents structure correct.

Permuting pages#

After all pages have been collected, you can re-arrange the pages in the PDF file by changing the Pages slice in the Pages object which the main PDF object has a reference to.

type Pages struct {
    Pages []*Page
}

For example you can do something like this:

pw.Pages.Pages[0], pw.Pages.Pages[1] = pw.Pages.Pages[1], pw.Pages.Pages[0]

to swap the first two pages. pw in this example is the main PDF object.

Writing pages to the PDF#

The PDF backend takes care of writing all the Page objects and the Pages object to the PDF. No user action is required.