Report
A report is a document with structure: numbered sections, a contents page that agrees with
them, a cover, and something repeated at the top and bottom of every page. The creator has
a component for each of those, and they all come together in Finalize, which runs
automatically when you write the file.
Invoices live here too. Creator.NewInvoice is a prebuilt layout rather than something you
assemble, so it shares little with the rest of the section, but it is the same kind of
job: a structured business document produced from data.
What gets built when
Draw calls go into the body in the order you make them. The front page and the table of
contents are generated at the end and prepended, which is why registering
CreateFrontPage after drawing your chapters still produces a cover on page 1.
Finalize does this in a specific sequence: it renders the front page onto a scratch
creator to count its pages, lays out the TOC to count its pages, adds that total to every
TOC page number and internal link, assembles the pages in order, shifts the recorded
chapter positions to match, and only then walks the finished page list running the
page-finalize, header and footer callbacks. Anything that needs final page numbers has to
be in one of those callbacks.
Chapters carry the structure
c.NewChapter(title) and chap.NewSubchapter(title) build the hierarchy, numbering
themselves as 1, 1.1, 1.2 and so on. A chapter accumulates content through
chap.Add and registers both a TOC line and an outline entry when you draw it.
SetIncludeInTOC(false) excludes a single chapter; c.AddTOC and c.AddOutlines control
the two features document-wide. Their defaults differ - AddOutlines is true out of
creator.New, AddTOC is not - so a report has to set AddTOC itself.
You never place a TOC line by hand in the normal case. The lines come from the chapters,
and the page numbers are corrected during Finalize. Adding lines manually with
toc.Add is for documents whose sections aren’t chapters.
Headers and footers are callbacks, not components
DrawHeader and DrawFooter hand you a Block sized to the page width by the
corresponding page margin - pageMargins.Top for the header, pageMargins.Bottom for the
footer. Content that doesn’t fit that height overlaps the body, so a report with a logo
header needs a generous top margin set before anything is drawn.
The args carry PageNum and TotalPages for the assembled document, plus a
Chapter *ChapterInfo with the number, title and level of the section the page belongs to,
which is what a running head like “1.2 Overview” is built from. It is nil on pages before
the first chapter heading, meaning the cover and the TOC.
Where to look
| Guide | Covers |
|---|---|
| Create PDF Report | The full assembly: chapters, TOC, cover page, header and footer, and how page numbering works. |
| Create PDF Report Landscape | Landscape pages, and why SetPageSize has to come before SetPageMargins. |
| Create PDF Custom Table of Contents | Replacing the built-in TOC layout with your own drawing code. |
| Tables in a Report | How the table-features example is organized as chapters, and TOC styling without a callback. |
| Invoices | Creator.NewInvoice, the built-in invoice layout. |
Tables inside a report are the same creator.Table documented in the
tables guides. For paragraphs and text styling see
text manipulation, and for markup-driven layout instead of Go
calls see templates.