Document
Multi-page documents, headers & footers, metadata, and page numbering
Multi-Page Documents
Create documents with multiple pages, each with its own content.
::pdf-example{pdf="/pdfs/examples/12_multi_page.pdf"}
{
"page": {"size": "A4", "margins": "20mm"},
"pages": [
{"body": [
{"row": {"cols": [{"span": 12, "elements": [
{"type": "text", "content": "Multi-Page Document", "style": {"size": 20, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "line"},
{"type": "spacer", "height": "10mm"}
]}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}}
]},
{"body": [
{"row": {"cols": [{"span": 12, "elements": [
{"type": "text", "content": "Multi-Page Document", "style": {"size": 20, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "line"},
{"type": "spacer", "height": "10mm"}
]}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}}
]},
{"body": [
{"row": {"cols": [{"span": 12, "elements": [
{"type": "text", "content": "Multi-Page Document", "style": {"size": 20, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "line"},
{"type": "spacer", "height": "10mm"}
]}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}}
]},
{"body": [
{"row": {"cols": [{"span": 12, "elements": [
{"type": "text", "content": "Multi-Page Document", "style": {"size": 20, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "line"},
{"type": "spacer", "height": "10mm"}
]}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}}
]},
{"body": [
{"row": {"cols": [{"span": 12, "elements": [
{"type": "text", "content": "Multi-Page Document", "style": {"size": 20, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "line"},
{"type": "spacer", "height": "10mm"}
]}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}},
{"row": {"cols": [{"span": 12, "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."}]}}
]}
]
}
::
Headers & Footers
Define headers and footers that repeat on every page.
::pdf-example{pdf="/pdfs/examples/13_header_footer.pdf"}
{
"page": {"size": "A4", "margins": "20mm"},
"header": [
{"row": {"cols": [
{"span": 6, "text": "ACME Corporation", "style": {"bold": true, "size": 10}},
{"span": 6, "text": "Confidential Report", "style": {"align": "right", "size": 10, "color": "gray(0.5)"}}
]}},
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "line", "line": {"color": "#1565C0", "thickness": "2pt"}},
{"type": "spacer", "height": "5mm"}
]}
]}}
],
"footer": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "spacer", "height": "5mm"},
{"type": "line", "line": {"color": "gray(0.7)"}},
{"type": "spacer", "height": "2mm"}
]}
]}},
{"row": {"cols": [
{"span": 6, "text": "Generated by gpdf", "style": {"size": 8, "color": "gray(0.5)"}},
{"span": 6, "text": "Confidential", "style": {"align": "right", "size": 8, "color": "gray(0.5)"}}
]}}
],
"pages": [
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Main Content Area", "style": {"size": 16, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This page demonstrates header and footer repeated on every page. The header contains the company name and document title. The footer contains generation info and a confidentiality notice."}
]}
]}}
]},
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Main Content Area", "style": {"size": 16, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This page demonstrates header and footer repeated on every page. The header contains the company name and document title. The footer contains generation info and a confidentiality notice."}
]}
]}}
]},
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Main Content Area", "style": {"size": 16, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This page demonstrates header and footer repeated on every page. The header contains the company name and document title. The footer contains generation info and a confidentiality notice."}
]}
]}}
]}
]
}
::
Metadata
Embed document metadata (title, author, subject, creator) in the PDF.
::pdf-example{pdf="/pdfs/examples/14_metadata.pdf"}
{
"page": {"size": "A4", "margins": "20mm"},
"metadata": {
"title": "Annual Report 2026",
"author": "gpdf Library",
"subject": "Example of document metadata",
"creator": "gpdf example_test.go"
},
"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Document with Metadata", "style": {"size": 20, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This PDF has the following metadata set:"},
{"type": "spacer", "height": "3mm"},
{"type": "text", "content": "Title: Annual Report 2026"},
{"type": "text", "content": "Author: gpdf Library"},
{"type": "text", "content": "Subject: Example of document metadata"},
{"type": "text", "content": "Creator: gpdf example_test.go"},
{"type": "text", "content": "Producer: gpdf (set automatically)"},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "Open the PDF properties in your viewer to verify.", "style": {"italic": true}}
]}
]}}
]
}
::
Page Numbering
Automatic page number and total page count in headers and footers.
::pdf-example{pdf="/pdfs/examples/26_page_number.pdf"}
{
"page": {"size": "A4", "margins": "20mm"},
"metadata": {"title": "Page Number Demo", "author": "gpdf"},
"header": [
{"row": {"cols": [
{"span": 6, "text": "Page Number Demo", "style": {"bold": true, "size": 10}},
{"span": 6, "elements": [
{"type": "totalPages", "style": {"align": "right", "size": 9, "color": "gray(0.5)"}}
]}
]}},
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "line", "line": {"color": "#1565C0"}},
{"type": "spacer", "height": "3mm"}
]}
]}}
],
"footer": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "spacer", "height": "3mm"},
{"type": "line", "line": {"color": "gray(0.7)"}},
{"type": "spacer", "height": "2mm"}
]}
]}},
{"row": {"cols": [
{"span": 6, "text": "Generated by gpdf", "style": {"size": 8, "color": "gray(0.5)"}},
{"span": 6, "elements": [
{"type": "pageNumber", "style": {"align": "right", "size": 8, "color": "gray(0.5)"}}
]}
]}}
],
"pages": [
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Introduction", "style": {"size": 18, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This is the content of the page. The footer displays the current page number, and the header shows the total number of pages in the document. Both are automatically updated after pagination, including on overflow pages."}
]}
]}}
]},
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Background", "style": {"size": 18, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This is the content of the page. The footer displays the current page number, and the header shows the total number of pages in the document. Both are automatically updated after pagination, including on overflow pages."}
]}
]}}
]},
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Analysis", "style": {"size": 18, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This is the content of the page. The footer displays the current page number, and the header shows the total number of pages in the document. Both are automatically updated after pagination, including on overflow pages."}
]}
]}}
]},
{"body": [
{"row": {"cols": [
{"span": 12, "elements": [
{"type": "text", "content": "Conclusion", "style": {"size": 18, "bold": true}},
{"type": "spacer", "height": "5mm"},
{"type": "text", "content": "This is the content of the page. The footer displays the current page number, and the header shows the total number of pages in the document. Both are automatically updated after pagination, including on overflow pages."}
]}
]}}
]}
]
}
::
Something unclear or missing on this page?