From e23cdc5d37068c6f32e5b585a410a79a5cfd0d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20W=C3=B6lk?= Date: Thu, 5 Sep 2024 16:15:23 +0200 Subject: [PATCH 1/2] fpdf: fix autobreak when next page already exists --- fpdf.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fpdf.go b/fpdf.go index f4ef7af..b4bff6f 100644 --- a/fpdf.go +++ b/fpdf.go @@ -2566,7 +2566,12 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr, borderStr string, ln int, f.ws = 0 f.out("0 Tw") } - f.AddPageFormat(f.curOrientation, f.curPageSize) + if f.PageNo() == f.PageCount() { + f.AddPageFormat(f.curOrientation, f.curPageSize) + } else { + f.page += 1 + f.y = f.tMargin + } if f.err != nil { return } From 50ace59598b4a95edec98e63f41268faf4d4cd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20W=C3=B6lk?= Date: Thu, 5 Sep 2024 17:35:26 +0200 Subject: [PATCH 2/2] restore current format after existing page break --- fpdf.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/fpdf.go b/fpdf.go index b4bff6f..675ebf3 100644 --- a/fpdf.go +++ b/fpdf.go @@ -2569,8 +2569,54 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr, borderStr string, ln int, if f.PageNo() == f.PageCount() { f.AddPageFormat(f.curOrientation, f.curPageSize) } else { + familyStr := f.fontFamily + style := f.fontStyle + if f.underline { + style += "U" + } + if f.strikeout { + style += "S" + } + fontsize := f.fontSizePt + lw := f.lineWidth + dc := f.color.draw + fc := f.color.fill + tc := f.color.text + cf := f.colorFlag + f.page += 1 f.y = f.tMargin + + // Set line cap style to current value + // f.out("2 J") + f.outf("%d J", f.capStyle) + // Set line join style to current value + f.outf("%d j", f.joinStyle) + // Set line width + f.lineWidth = lw + f.outf("%.2f w", lw*f.k) + // Set dash pattern + if len(f.dashArray) > 0 { + f.outputDashPattern() + } + // Set font + if familyStr != "" { + f.SetFont(familyStr, style, fontsize) + if f.err != nil { + return + } + } + // Set colors + f.color.draw = dc + if dc.str != "0 G" { + f.out(dc.str) + } + f.color.fill = fc + if fc.str != "0 g" { + f.out(fc.str) + } + f.color.text = tc + f.colorFlag = cf } if f.err != nil { return