Business Documents
Invoice
Professional invoice with company header, billing details, itemized table, and totals.
doc := template.New(
template.WithPageSize(document.A4),
template.WithMargins(document.UniformEdges(document.Mm(20))),
template.WithMetadata(document.DocumentMetadata{
Title: "Invoice #INV-2026-001",
Author: "ACME Corporation",
}),
)
page := doc.AddPage()
// Company header
page.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("ACME Corporation", template.FontSize(24), template.Bold(),
template.TextColor(pdf.RGBHex(0x1A237E)))
c.Text("123 Business Street")
c.Text("Suite 100")
c.Text("San Francisco, CA 94105")
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("INVOICE", template.FontSize(28), template.Bold(), template.AlignRight(),
template.TextColor(pdf.RGBHex(0x1A237E)))
c.Spacer(document.Mm(3))
c.Text("#INV-2026-001", template.AlignRight(), template.FontSize(12))
c.Text("Date: March 1, 2026", template.AlignRight())
c.Text("Due: March 31, 2026", template.AlignRight())
})
})
// Separator
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(5))
c.Line(template.LineColor(pdf.RGBHex(0x1A237E)), template.LineThickness(document.Pt(2)))
c.Spacer(document.Mm(5))
})
})
// Bill to
page.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Bill To:", template.Bold(), template.TextColor(pdf.Gray(0.4)))
c.Spacer(document.Mm(2))
c.Text("John Smith", template.Bold())
c.Text("Tech Solutions Inc.")
c.Text("456 Client Avenue")
c.Text("New York, NY 10001")
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Payment Info:", template.Bold(), template.TextColor(pdf.Gray(0.4)))
c.Spacer(document.Mm(2))
c.Text("Bank: First National Bank")
c.Text("Account: 1234-5678-9012")
c.Text("Routing: 021000021")
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(10))
})
})
// Items table
headerBlue := pdf.RGBHex(0x1A237E)
stripeGray := pdf.RGBHex(0xF5F5F5)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Table(
[]string{"Description", "Qty", "Unit Price", "Amount"},
[][]string{
{"Web Development - Frontend", "40 hrs", "$150.00", "$6,000.00"},
{"Web Development - Backend", "60 hrs", "$150.00", "$9,000.00"},
{"UI/UX Design", "20 hrs", "$120.00", "$2,400.00"},
{"Database Design", "15 hrs", "$130.00", "$1,950.00"},
{"QA Testing", "25 hrs", "$100.00", "$2,500.00"},
{"Project Management", "10 hrs", "$140.00", "$1,400.00"},
},
template.ColumnWidths(40, 15, 20, 25),
template.TableHeaderStyle(
template.TextColor(pdf.White),
template.BgColor(headerBlue),
),
template.TableStripe(stripeGray),
)
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(5))
})
})
// Totals
page.AutoRow(func(r *template.RowBuilder) {
r.Col(8, func(c *template.ColBuilder) {
// empty left side
})
r.Col(4, func(c *template.ColBuilder) {
c.Text("Subtotal: $23,250.00", template.AlignRight())
c.Text("Tax (10%): $2,325.00", template.AlignRight())
c.Spacer(document.Mm(2))
c.Line(template.LineThickness(document.Pt(1)))
c.Spacer(document.Mm(2))
c.Text("Total: $25,575.00", template.AlignRight(),
template.Bold(), template.FontSize(14))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(15))
c.Line(template.LineColor(pdf.Gray(0.8)))
c.Spacer(document.Mm(3))
c.Text("Thank you for your business!", template.AlignCenter(),
template.Italic(), template.TextColor(pdf.Gray(0.5)))
})
})
Report
Multi-page quarterly report with headers, footers, key metrics, revenue and expense tables.
doc := template.New(
template.WithPageSize(document.A4),
template.WithMargins(document.UniformEdges(document.Mm(20))),
template.WithMetadata(document.DocumentMetadata{
Title: "Quarterly Report Q1 2026",
Author: "ACME Corporation",
Subject: "Q1 2026 Financial Summary",
}),
)
// Header for all pages
doc.Header(func(p *template.PageBuilder) {
p.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("ACME Corp", template.Bold(), template.FontSize(9),
template.TextColor(pdf.RGBHex(0x1565C0)))
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Q1 2026 Report", template.AlignRight(), template.FontSize(9),
template.TextColor(pdf.Gray(0.5)))
})
})
p.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Line(template.LineColor(pdf.RGBHex(0x1565C0)))
c.Spacer(document.Mm(3))
})
})
})
// Footer for all pages
doc.Footer(func(p *template.PageBuilder) {
p.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(3))
c.Line(template.LineColor(pdf.Gray(0.8)))
c.Spacer(document.Mm(2))
})
})
p.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Confidential - For Internal Use Only",
template.AlignCenter(), template.FontSize(7), template.TextColor(pdf.Gray(0.5)))
})
})
})
// --- Page 1: Title & Executive Summary ---
page1 := doc.AddPage()
page1.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(20))
c.Text("Quarterly Report", template.FontSize(28), template.Bold(),
template.AlignCenter(), template.TextColor(pdf.RGBHex(0x1A237E)))
c.Text("Q1 2026 - Financial Summary", template.FontSize(16),
template.AlignCenter(), template.TextColor(pdf.Gray(0.4)))
c.Spacer(document.Mm(15))
c.Line(template.LineColor(pdf.RGBHex(0x1A237E)), template.LineThickness(document.Pt(2)))
c.Spacer(document.Mm(10))
})
})
page1.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Executive Summary", template.FontSize(16), template.Bold())
c.Spacer(document.Mm(3))
c.Text("This report presents the financial performance of ACME Corporation " +
"for the first quarter of 2026. Revenue increased by 15% compared to Q4 2025, " +
"driven primarily by strong growth in the cloud services division. " +
"Operating margins improved to 22%, up from 19% in the previous quarter.")
c.Spacer(document.Mm(5))
c.Text("Key highlights include the successful launch of three new product lines, " +
"expansion into the European market, and a 20% reduction in customer churn rate. " +
"The company remains well-positioned for continued growth throughout 2026.")
})
})
// Key metrics in grid
page1.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(10))
c.Text("Key Metrics", template.FontSize(14), template.Bold())
c.Spacer(document.Mm(3))
})
})
page1.AutoRow(func(r *template.RowBuilder) {
r.Col(3, func(c *template.ColBuilder) {
c.Text("Revenue", template.TextColor(pdf.Gray(0.5)), template.FontSize(9))
c.Text("$12.5M", template.FontSize(18), template.Bold(),
template.TextColor(pdf.RGBHex(0x2E7D32)))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Growth", template.TextColor(pdf.Gray(0.5)), template.FontSize(9))
c.Text("+15%", template.FontSize(18), template.Bold(),
template.TextColor(pdf.RGBHex(0x2E7D32)))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Customers", template.TextColor(pdf.Gray(0.5)), template.FontSize(9))
c.Text("2,450", template.FontSize(18), template.Bold(),
template.TextColor(pdf.RGBHex(0x1565C0)))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Margin", template.TextColor(pdf.Gray(0.5)), template.FontSize(9))
c.Text("22%", template.FontSize(18), template.Bold(),
template.TextColor(pdf.RGBHex(0x1565C0)))
})
})
// --- Page 2: Financial Details ---
page2 := doc.AddPage()
page2.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Revenue Breakdown", template.FontSize(16), template.Bold())
c.Spacer(document.Mm(5))
})
})
darkHeader := pdf.RGBHex(0x1A237E)
stripe := pdf.RGBHex(0xF5F5F5)
page2.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Table(
[]string{"Division", "Q1 2026", "Q4 2025", "Change"},
[][]string{
{"Cloud Services", "$5,200,000", "$4,100,000", "+26.8%"},
{"Enterprise Software", "$3,800,000", "$3,500,000", "+8.6%"},
{"Consulting", "$2,100,000", "$1,900,000", "+10.5%"},
{"Support & Maintenance", "$1,400,000", "$1,350,000", "+3.7%"},
},
template.ColumnWidths(35, 22, 22, 21),
template.TableHeaderStyle(
template.TextColor(pdf.White),
template.BgColor(darkHeader),
),
template.TableStripe(stripe),
)
c.Spacer(document.Mm(10))
})
})
page2.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Expense Summary", template.FontSize(16), template.Bold())
c.Spacer(document.Mm(5))
})
})
page2.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Table(
[]string{"Category", "Amount", "% of Revenue"},
[][]string{
{"Personnel", "$5,500,000", "44.0%"},
{"Infrastructure", "$1,800,000", "14.4%"},
{"Marketing", "$1,200,000", "9.6%"},
{"R&D", "$950,000", "7.6%"},
{"General & Admin", "$300,000", "2.4%"},
},
template.ColumnWidths(40, 30, 30),
template.TableHeaderStyle(
template.TextColor(pdf.White),
template.BgColor(darkHeader),
),
template.TableStripe(stripe),
)
c.Spacer(document.Mm(10))
})
})
// Two-column commentary
page2.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Highlights", template.Bold(), template.TextColor(pdf.RGBHex(0x2E7D32)))
c.Spacer(document.Mm(2))
c.Text("Cloud services revenue grew 26.8%, exceeding projections by 5%. " +
"New enterprise clients added: 47.")
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Challenges", template.Bold(), template.TextColor(pdf.RGBHex(0xC62828)))
c.Spacer(document.Mm(2))
c.Text("Infrastructure costs rose 12% due to scaling needs. " +
"Two major client renewals deferred to Q2.")
})
})
QR Code
Generate QR codes with configurable size and error correction levels.
doc := template.New(
template.WithPageSize(document.A4),
template.WithMargins(document.UniformEdges(document.Mm(20))),
template.WithMetadata(document.DocumentMetadata{
Title: "QR Code Examples",
Author: "gpdf",
}),
)
page := doc.AddPage()
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("QR Code Examples", template.FontSize(18), template.Bold())
c.Spacer(document.Mm(5))
})
})
// Basic QR code
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Basic QR code (URL):")
c.Spacer(document.Mm(2))
c.QRCode("https://gpdf.dev")
c.Spacer(document.Mm(5))
})
})
// QR codes with different sizes side by side
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("QR codes with different sizes:")
c.Spacer(document.Mm(2))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(4, func(c *template.ColBuilder) {
c.Text("20mm", template.FontSize(9), template.TextColor(pdf.Gray(0.4)))
c.QRCode("https://gpdf.dev", template.QRSize(document.Mm(20)))
})
r.Col(4, func(c *template.ColBuilder) {
c.Text("30mm", template.FontSize(9), template.TextColor(pdf.Gray(0.4)))
c.QRCode("https://gpdf.dev", template.QRSize(document.Mm(30)))
})
r.Col(4, func(c *template.ColBuilder) {
c.Text("40mm", template.FontSize(9), template.TextColor(pdf.Gray(0.4)))
c.QRCode("https://gpdf.dev", template.QRSize(document.Mm(40)))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(5))
})
})
// QR codes with different EC levels
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Error correction levels (L / M / Q / H):")
c.Spacer(document.Mm(2))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(3, func(c *template.ColBuilder) {
c.Text("Level L", template.FontSize(9))
c.QRCode("HELLO", template.QRSize(document.Mm(25)),
template.QRErrorCorrection(qrcode.LevelL))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Level M", template.FontSize(9))
c.QRCode("HELLO", template.QRSize(document.Mm(25)),
template.QRErrorCorrection(qrcode.LevelM))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Level Q", template.FontSize(9))
c.QRCode("HELLO", template.QRSize(document.Mm(25)),
template.QRErrorCorrection(qrcode.LevelQ))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Level H", template.FontSize(9))
c.QRCode("HELLO", template.QRSize(document.Mm(25)),
template.QRErrorCorrection(qrcode.LevelH))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(5))
})
})
// Japanese content
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Japanese content:")
c.Spacer(document.Mm(2))
c.QRCode("こんにちは世界", template.QRSize(document.Mm(30)))
})
})
Barcode
Code 128 barcodes with configurable width and height.
doc := template.New(
template.WithPageSize(document.A4),
template.WithMargins(document.UniformEdges(document.Mm(20))),
template.WithMetadata(document.DocumentMetadata{
Title: "Barcode Examples",
Author: "gpdf",
}),
)
page := doc.AddPage()
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Barcode Examples", template.FontSize(18), template.Bold())
c.Spacer(document.Mm(5))
})
})
// Basic barcode
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Code 128 barcode:")
c.Spacer(document.Mm(2))
c.Barcode("INV-2026-0001")
c.Spacer(document.Mm(5))
})
})
// Barcodes with explicit sizes
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("With display width (80mm):")
c.Spacer(document.Mm(2))
c.Barcode("PRODUCT-A-12345", template.BarcodeWidth(document.Mm(80)))
c.Spacer(document.Mm(5))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("With display height (10mm):")
c.Spacer(document.Mm(2))
c.Barcode("SMALL-BAR", template.BarcodeHeight(document.Mm(10)))
c.Spacer(document.Mm(5))
})
})
// Numeric data (optimized with Code C)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Numeric data (Code C optimization):")
c.Spacer(document.Mm(2))
c.Barcode("1234567890")
c.Spacer(document.Mm(5))
})
})
// Barcodes in columns
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Barcodes in columns:")
c.Spacer(document.Mm(2))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Item A", template.FontSize(9))
c.Barcode("ITEM-A-001", template.BarcodeWidth(document.Mm(60)))
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Item B", template.FontSize(9))
c.Barcode("ITEM-B-002", template.BarcodeWidth(document.Mm(60)))
})
})
QR Code + Barcode Invoice
Professional invoice combining QR code for online payment and barcode for reference scanning.
doc := template.New(
template.WithPageSize(document.A4),
template.WithMargins(document.UniformEdges(document.Mm(20))),
template.WithMetadata(document.DocumentMetadata{
Title: "Invoice with QR/Barcode",
Author: "ACME Corporation",
}),
)
page := doc.AddPage()
// Header with QR code
page.AutoRow(func(r *template.RowBuilder) {
r.Col(8, func(c *template.ColBuilder) {
c.Text("ACME Corporation", template.FontSize(22), template.Bold(),
template.TextColor(pdf.RGBHex(0x1A237E)))
c.Text("Invoice #INV-2026-042", template.FontSize(12),
template.TextColor(pdf.Gray(0.4)))
})
r.Col(4, func(c *template.ColBuilder) {
c.QRCode("https://pay.acme.com/inv/2026-042",
template.QRSize(document.Mm(30)),
template.QRErrorCorrection(qrcode.LevelH))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(3))
c.Line(template.LineColor(pdf.RGBHex(0x1A237E)),
template.LineThickness(document.Pt(2)))
c.Spacer(document.Mm(5))
})
})
// Bill to
page.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Bill To:", template.Bold(), template.TextColor(pdf.Gray(0.4)))
c.Spacer(document.Mm(2))
c.Text("Jane Doe", template.Bold())
c.Text("Tech Solutions Inc.")
c.Text("456 Client Avenue")
c.Text("New York, NY 10001")
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Date: March 1, 2026", template.AlignRight())
c.Text("Due: March 31, 2026", template.AlignRight())
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(8))
})
})
// Items table
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Table(
[]string{"Description", "Qty", "Price", "Amount"},
[][]string{
{"Web Development", "40 hrs", "$150.00", "$6,000.00"},
{"UI/UX Design", "20 hrs", "$120.00", "$2,400.00"},
{"QA Testing", "15 hrs", "$100.00", "$1,500.00"},
},
template.ColumnWidths(40, 15, 20, 25),
template.TableHeaderStyle(
template.TextColor(pdf.White),
template.BgColor(pdf.RGBHex(0x1A237E)),
),
template.TableStripe(pdf.RGBHex(0xF5F5F5)),
)
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(8, func(c *template.ColBuilder) {})
r.Col(4, func(c *template.ColBuilder) {
c.Spacer(document.Mm(3))
c.Text("Total: $9,900.00", template.AlignRight(),
template.Bold(), template.FontSize(14))
})
})
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Spacer(document.Mm(10))
c.Line(template.LineColor(pdf.Gray(0.8)))
c.Spacer(document.Mm(5))
})
})
// Barcode at bottom for scanning
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Order Reference:", template.FontSize(9),
template.TextColor(pdf.Gray(0.4)))
c.Spacer(document.Mm(2))
c.Barcode("INV-2026-042", template.BarcodeWidth(document.Mm(100)),
template.BarcodeHeight(document.Mm(15)))
c.Spacer(document.Mm(5))
c.Text("Scan QR code to pay online", template.AlignCenter(),
template.Italic(), template.FontSize(9),
template.TextColor(pdf.Gray(0.5)))
})
})