Skip to content
Creating Documents

Creating Documents

Creating a document from scratch means the creator package. creator.New() returns a Creator, every component is made from it, c.Draw puts a component into the document, and c.WriteToFile produces the PDF. Reports, invoices, tables, images and barcodes are all components drawn into that one flow.

Drawn content stacks down the page in the order you draw it and continues onto a new page when it runs out of room. SetPos(x, y) takes a component out of that flow and pins it somewhere instead. Those coordinates start at the top left of the page and y grows downward, which is upside down compared to PDF’s own user space; how PDF coordinate systems work has the conversion.

Two components lay content out in cells. Table takes a column count and fills cells in order, starting a new row once the current one is full. Grid makes rows explicit objects you ask for cells from. Grid arrived in v4 as the more predictable of the two and is usually the better starting point for new code, though header rows repeated on every page still only exist on Table.

Last updated on