Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ body:
id: gpdf-version
attributes:
label: gpdf Version
placeholder: "v1.0.2"
placeholder: "v1.0.3"
validations:
required: true

Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed
- Multi-page table support — tables inside Row/Col now automatically split across pages
- `layoutHorizontal` propagates child overflow to the paginator
- Table headers repeat on each continuation page (existing `layoutTable` logic)

## [1.0.2] - 2026-03-23

### Added
Expand Down Expand Up @@ -102,8 +107,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- Reed-Solomon coefficient order in QR code encoder
- binary.Write return value handling for errcheck lint

[Unreleased]: https://github.com/gpdf-dev/gpdf/compare/v1.0.2...HEAD
[1.0.2]: https://github.com/gpdf-dev/gpdf/compare/v1.0.0...v1.0.2
[Unreleased]: https://github.com/gpdf-dev/gpdf/compare/v1.0.3...HEAD
[1.0.2]: https://github.com/gpdf-dev/gpdf/compare/v1.0.0...v1.0.3
[1.0.0]: https://github.com/gpdf-dev/gpdf/compare/v0.9.0...v1.0.0
[0.9.0]: https://github.com/gpdf-dev/gpdf/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/gpdf-dev/gpdf/compare/v0.5.0...v0.8.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Go Reference](https://pkg.go.dev/badge/github.com/gpdf-dev/gpdf.svg)](https://pkg.go.dev/github.com/gpdf-dev/gpdf)
[![CI](https://github.com/gpdf-dev/gpdf/actions/workflows/check-code.yml/badge.svg)](https://github.com/gpdf-dev/gpdf/actions/workflows/check-code.yml)
![coverage](https://img.shields.io/badge/coverage-86.5%25-green)
![coverage](https://img.shields.io/badge/coverage-86.3%25-green)
[![Go Report Card](https://goreportcard.com/badge/github.com/gpdf-dev/gpdf)](https://goreportcard.com/report/github.com/gpdf-dev/gpdf)
[![Go Version](https://img.shields.io/badge/Go-%3E%3D1.22-blue)](https://go.dev/)
[![Website](https://img.shields.io/badge/Website-gpdf.dev-blue)](https://gpdf.dev/)
Expand Down
12 changes: 6 additions & 6 deletions _benchmark/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ go 1.24
replace github.com/gpdf-dev/gpdf => ../

require (
github.com/go-pdf/fpdf v1.0.2
github.com/go-pdf/fpdf v1.0.3
github.com/johnfercher/maroto/v2 v2.3.3
github.com/gpdf-dev/gpdf v1.0.2
github.com/gpdf-dev/gpdf v1.0.3
github.com/signintech/gopdf v0.36.0
golang.org/x/image v0.18.0
)

require (
github.com/boombuler/barcode v1.0.2 // indirect
github.com/boombuler/barcode v1.0.3 // indirect
github.com/f-amaral/go-async v0.3.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hhrutter/lzw v1.0.2 // indirect
github.com/hhrutter/tiff v1.0.2 // indirect
github.com/hhrutter/lzw v1.0.3 // indirect
github.com/hhrutter/tiff v1.0.3 // indirect
github.com/johnfercher/go-tree v1.0.5 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/pdfcpu/pdfcpu v0.6.0 // indirect
github.com/phpdave11/gofpdf v1.4.3 // indirect
github.com/phpdave11/gofpdi v1.0.25 // indirect
github.com/phpdave11/gofpdi v1.0.35 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/text v0.22.0 // indirect
Expand Down
30 changes: 15 additions & 15 deletions _benchmark/go.sum
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.2 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.3/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.3 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
github.com/boombuler/barcode v1.0.3/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/f-amaral/go-async v0.3.0 h1:h4kLsX7aKfdWaHvV0lf+/EE3OIeCzyeDYJDb/vDZUyg=
github.com/f-amaral/go-async v0.3.0/go.mod h1:Hz5Qr6DAWpbTTUjytnrg1WIsDgS7NtOei5y8SipYS7U=
github.com/go-pdf/fpdf v1.0.2 h1:PPvSaUuo1iMi9KkaAn90NuKi+P4gwMedWPHhj8YlJQw=
github.com/go-pdf/fpdf v1.0.2/go.mod h1:oO8N111TkmKb9D7VvWGLvLJlaZUQVPM+6V42pp3iV4Y=
github.com/go-pdf/fpdf v1.0.3 h1:PPvSaUuo1iMi9KkaAn90NuKi+P4gwMedWPHhj8YlJQw=
github.com/go-pdf/fpdf v1.0.3/go.mod h1:oO8N111TkmKb9D7VvWGLvLJlaZUQVPM+6V42pp3iV4Y=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hhrutter/lzw v1.0.2 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0=
github.com/hhrutter/lzw v1.0.2/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo=
github.com/hhrutter/tiff v1.0.2 h1:MIus8caHU5U6823gx7C6jrfoEvfSTGtEFRiM8/LOzC0=
github.com/hhrutter/tiff v1.0.2/go.mod h1:zU/dNgDm0cMIa8y8YwcYBeuEEveI4B0owqHyiPpJPHc=
github.com/hhrutter/lzw v1.0.3 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0=
github.com/hhrutter/lzw v1.0.3/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo=
github.com/hhrutter/tiff v1.0.3 h1:MIus8caHU5U6823gx7C6jrfoEvfSTGtEFRiM8/LOzC0=
github.com/hhrutter/tiff v1.0.3/go.mod h1:zU/dNgDm0cMIa8y8YwcYBeuEEveI4B0owqHyiPpJPHc=
github.com/johnfercher/go-tree v1.0.5 h1:zpgVhJsChavzhKdxhQiCJJzcSY3VCT9oal2JoA2ZevY=
github.com/johnfercher/go-tree v1.0.5/go.mod h1:DUO6QkXIFh1K7jeGBIkLCZaeUgnkdQAsB64FDSoHswg=
github.com/johnfercher/maroto/v2 v2.3.3 h1:oeXsBnoecaMgRDwN0Cstjoe4rug3lKpOanuxuHKPqQE=
github.com/johnfercher/maroto/v2 v2.3.3/go.mod h1:KNv102TwUrlVgZGukzlIbhkG6l/WaCD6pzu6aWGVjBI=
github.com/jung-kurt/gofpdf v1.0.2/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.0.3/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pdfcpu/pdfcpu v0.6.0 h1:z4kARP5bcWa39TTYMcN/kjBnm7MvhTWjXgeYmkdAGMI=
github.com/pdfcpu/pdfcpu v0.6.0/go.mod h1:kmpD0rk8YnZj0l3qSeGBlAB+XszHUgNv//ORH/E7EYo=
github.com/phpdave11/gofpdf v1.4.3 h1:M/zHvS8FO3zh9tUd2RCOPEjyuVcs281FCyF22Qlz/IA=
github.com/phpdave11/gofpdf v1.4.3/go.mod h1:MAwzoUIgD3J55u0rxIG2eu37c+XWhBtXSpPAhnQXf/o=
github.com/phpdave11/gofpdi v1.0.24-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.25 h1:iJazY1BQ07I9s7N5EWjBO1YbhmKfHGxNligUv/Rw4Lc=
github.com/phpdave11/gofpdi v1.0.25/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.34-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.35 h1:iJazY1BQ07I9s7N5EWjBO1YbhmKfHGxNligUv/Rw4Lc=
github.com/phpdave11/gofpdi v1.0.35/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.2 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.3 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.3/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
100 changes: 100 additions & 0 deletions _examples/builder/33_multi_page_table_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package builder_test

import (
"fmt"
"testing"

"github.com/gpdf-dev/gpdf/_examples/testutil"
"github.com/gpdf-dev/gpdf/document"
"github.com/gpdf-dev/gpdf/pdf"
"github.com/gpdf-dev/gpdf/template"
)

// TestExample_33_MultiPageTable verifies whether a large table automatically
// splits across multiple pages when its content exceeds the available space.
func TestExample_33_MultiPageTable(t *testing.T) {
doc := template.New(
template.WithPageSize(document.A4),
template.WithMargins(document.UniformEdges(document.Mm(15))),
)

// Header/footer to verify they repeat on every page.
doc.Header(func(p *template.PageBuilder) {
p.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Multi-Page Table Test", template.Bold(), template.FontSize(9))
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Header", 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()
c.Spacer(document.Mm(3))
})
})
})

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()
})
})
p.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Footer - Page Break Test",
template.AlignCenter(), template.FontSize(8), template.TextColor(pdf.Gray(0.5)))
})
})
})

// Generate 100 rows — far more than a single A4 page can hold.
rows := make([][]string, 100)
for i := range rows {
rows[i] = []string{
fmt.Sprintf("%d", i+1),
fmt.Sprintf("Product-%04d", i+1),
fmt.Sprintf("Category %c", 'A'+rune(i%5)),
fmt.Sprintf("$%d.%02d", 10+i*3, (i*7)%100),
fmt.Sprintf("%d", 100+i*10),
}
}

page := doc.AddPage()

page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Large Table — Auto Page Break Test", template.FontSize(16), template.Bold())
c.Spacer(document.Mm(5))
})
})

page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Table(
[]string{"#", "Product", "Category", "Price", "Stock"},
rows,
template.ColumnWidths(8, 30, 22, 20, 20),
template.TableHeaderStyle(
template.TextColor(pdf.White),
template.BgColor(pdf.RGBHex(0x1A237E)),
),
template.TableStripe(pdf.RGBHex(0xF5F5F5)),
)
})
})

data, err := doc.Generate()
if err != nil {
t.Fatalf("Generate failed: %v", err)
}
testutil.AssertValidPDF(t, data)
testutil.WritePDF(t, "33_multi_page_table.pdf", data)

// Log the PDF size so we can check it produced meaningful output.
t.Logf("Generated PDF: %d bytes", len(data))
}
4 changes: 2 additions & 2 deletions _validation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
)

require (
github.com/hhrutter/lzw v1.0.2 // indirect
github.com/hhrutter/tiff v1.0.2 // indirect
github.com/hhrutter/lzw v1.0.3 // indirect
github.com/hhrutter/tiff v1.0.3 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
Expand Down
8 changes: 4 additions & 4 deletions _validation/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/hhrutter/lzw v1.0.2 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0=
github.com/hhrutter/lzw v1.0.2/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo=
github.com/hhrutter/tiff v1.0.2 h1:MIus8caHU5U6823gx7C6jrfoEvfSTGtEFRiM8/LOzC0=
github.com/hhrutter/tiff v1.0.2/go.mod h1:zU/dNgDm0cMIa8y8YwcYBeuEEveI4B0owqHyiPpJPHc=
github.com/hhrutter/lzw v1.0.3 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0=
github.com/hhrutter/lzw v1.0.3/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo=
github.com/hhrutter/tiff v1.0.3 h1:MIus8caHU5U6823gx7C6jrfoEvfSTGtEFRiM8/LOzC0=
github.com/hhrutter/tiff v1.0.3/go.mod h1:zU/dNgDm0cMIa8y8YwcYBeuEEveI4B0owqHyiPpJPHc=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pdfcpu/pdfcpu v0.9.1 h1:q8/KlBdHjkE7ZJU4ofhKG5Rjf7M6L324CVM6BMDySao=
Expand Down
43 changes: 43 additions & 0 deletions document/layout/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ func (bl *BlockLayout) layoutHorizontal(node document.DocumentNode, constraints
}

var placed []PlacedNode
childResults := make([]Result, len(children))
cursorX := 0.0
maxHeight := 0.0
hasOverflow := false

for i, child := range children {
if child == nil {
Expand All @@ -345,6 +347,10 @@ func (bl *BlockLayout) layoutHorizontal(node document.DocumentNode, constraints
}

childResult := bl.layoutChild(child, childConstraints)
childResults[i] = childResult
if childResult.Overflow != nil {
hasOverflow = true
}

placed = append(placed, PlacedNode{
Node: child,
Expand Down Expand Up @@ -373,6 +379,9 @@ func (bl *BlockLayout) layoutHorizontal(node document.DocumentNode, constraints
stretchPlacedNodes(placed, finalContentHeight)

totalHeight := margin.Top + borderWidths.Top + padding.Top + finalContentHeight + padding.Bottom + borderWidths.Bottom + margin.Bottom

overflow := buildHorizontalOverflow(children, childResults, hasOverflow, style)

return Result{
Bounds: document.Rectangle{
X: 0,
Expand All @@ -381,6 +390,40 @@ func (bl *BlockLayout) layoutHorizontal(node document.DocumentNode, constraints
Height: totalHeight,
},
Children: placed,
Overflow: overflow,
}
}

// buildHorizontalOverflow creates an overflow horizontal box when any column
// child overflowed. Columns that fit entirely get an empty placeholder with
// the same width; columns with overflow carry their overflow content.
func buildHorizontalOverflow(children []document.DocumentNode, childResults []Result, hasOverflow bool, style document.Style) document.DocumentNode {
if !hasOverflow {
return nil
}
overflowChildren := make([]document.DocumentNode, len(children))
for i, child := range children {
if child == nil {
continue
}
if childResults[i].Overflow != nil {
overflowChildren[i] = childResults[i].Overflow
} else {
placeholder := &document.Box{}
if box, ok := child.(*document.Box); ok {
placeholder.BoxStyle.Width = box.BoxStyle.Width
}
overflowChildren[i] = placeholder
}
}
return &document.Box{
Content: overflowChildren,
BoxStyle: document.BoxStyle{
Direction: document.DirectionHorizontal,
Margin: style.Margin,
Padding: style.Padding,
Border: style.Border,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/buildinfo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package buildinfo

// Version is the library version. It is the single source of truth used by
// the public gpdf.Version constant and the default PDF Producer metadata.
const Version = "1.0.1"
const Version = "1.0.3"
Loading