Report

Overview

The Report component generates a structured report PDF with title page, sections, key metrics, and data tables. Ideal for business reports, quarterly reviews, and analytics summaries.

Usage

import "github.com/gpdf-dev/gpdf/template"

doc := template.Report(template.ReportData{
    Title:    "Quarterly Report",
    Subtitle: "Q1 2026 - Financial Summary",
    Author:   "ACME Corporation",
    Date:     "April 1, 2026",
    Sections: []template.ReportSection{
        {
            Title: "Executive Summary",
            Content: "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.",
            Metrics: []template.ReportMetric{
                {Label: "Revenue", Value: "$12.5M", ColorHex: 0x2E7D32},
                {Label: "Growth", Value: "+15%", ColorHex: 0x2E7D32},
                {Label: "Customers", Value: "2,450", ColorHex: 0x1565C0},
                {Label: "Margin", Value: "22%", ColorHex: 0x1565C0},
            },
        },
        {
            Title: "Revenue Breakdown",
            Table: &template.ReportTable{
                Header:       []string{"Division", "Q1 2026", "Q4 2025", "Change"},
                ColumnWidths: []float64{35, 22, 22, 21},
                Rows: [][]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%"},
                },
            },
        },
        {
            Title: "Expense Summary",
            Table: &template.ReportTable{
                Header:       []string{"Category", "Amount", "% of Revenue"},
                ColumnWidths: []float64{40, 30, 30},
                Rows: [][]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%"},
                },
            },
        },
    },
})

data, err := doc.Generate()
┌─ Page 1 (Title) ─────────────────────────────────┐
│                                                   │
│                                                   │
│           Quarterly Report                        │
│           Q1 2026 - Financial Summary             │
│                                                   │
│           ACME Corporation                        │
│           April 1, 2026                           │
│                                                   │
│                                                   │
└───────────────────────────────────────────────────┘

┌─ Page 2 ──────────────────────────────────────────┐
│                                                   │
│  Executive Summary                                │
│  ──────────────────────────────────────────────── │
│  This report presents the financial performance   │
│  of ACME Corporation for Q1 2026...               │
│                                                   │
│  ┌──────────┬──────────┬──────────┬──────────┐    │
│  │ Revenue  │  Growth  │Customers │  Margin  │    │
│  │ $12.5M   │  +15%    │  2,450   │   22%    │    │
│  └──────────┴──────────┴──────────┴──────────┘    │
│                                                   │
│  Revenue Breakdown                                │
│  ──────────────────────────────────────────────── │
│  ┌────────────────┬──────────┬──────────┬──────┐  │
│  │ Division       │ Q1 2026  │ Q4 2025  │Change│  │
│  ├────────────────┼──────────┼──────────┼──────┤  │
│  │ Cloud Services │$5,200,000│$4,100,000│+26.8%│  │
│  │ Enterprise SW  │$3,800,000│$3,500,000│ +8.6%│  │
│  │ Consulting     │$2,100,000│$1,900,000│+10.5%│  │
│  │ Support        │$1,400,000│$1,350,000│ +3.7%│  │
│  └────────────────┴──────────┴──────────┴──────┘  │
│                                                   │
└───────────────────────────────────────────────────┘

Data Types

ReportData

FieldTypeDescription
TitlestringReport title
SubtitlestringReport subtitle
AuthorstringAuthor / organization name
DatestringReport date
Sections[]ReportSectionReport sections

ReportSection

FieldTypeDescription
TitlestringSection heading
ContentstringSection body text
Metrics[]ReportMetricKey metrics displayed as cards
Table*ReportTableOptional data table

ReportMetric

type ReportMetric struct {
    Label    string
    Value    string
    ColorHex uint32    // Hex color for the value (e.g., 0x2E7D32)
}

ReportTable

type ReportTable struct {
    Header       []string
    ColumnWidths []float64
    Rows         [][]string
}

Customization

doc := template.Report(reportData,
    template.WithPageSize(document.Letter),
    template.WithFont("Inter", fontData),
)

Using the Facade

import "github.com/gpdf-dev/gpdf"

doc := gpdf.NewReport(reportData)