From 412d885ded2ae0364f78168e8e88c9451c61d32b Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 10 Nov 2018 14:21:54 -0500 Subject: Add an example for Paul Montag's page box feature --- README.md | 7 ++++--- def.go | 1 + doc.go | 8 ++++---- fpdf.go | 16 ++++++++++++---- fpdf_test.go | 6 +----- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2a8d606..c26dfcb 100644 --- a/README.md +++ b/README.md @@ -221,9 +221,10 @@ account when calculating image size. Paulo Coutinho provided support for static embedded fonts. Dan Meyers added support for embedded JavaScript. David Fish added a generic alias-replacement function to enable, among other things, table of contents functionality. Andy Bakun identified and corrected a problem in -which the internal catalogs were not sorted stably. d1ngd0 added encoding and -decoding functionality for templates, including images that are embedded in -templates; this allows templates to be stored independently of gofpdf. +which the internal catalogs were not sorted stably. Paul Montag added encoding +and decoding functionality for templates, including images that are embedded in +templates; this allows templates to be stored independently of gofpdf. Paul +also added support for page boxes used in printing PDF documents. ## Roadmap diff --git a/def.go b/def.go index ba96b2a..2bbb572 100644 --- a/def.go +++ b/def.go @@ -474,6 +474,7 @@ type Pdf interface { Writef(h float64, fmtStr string, args ...interface{}) } +// PageBox defines the coordinates and extent of the various page box types type PageBox struct { SizeType PointType diff --git a/doc.go b/doc.go index 534b1d7..deb9227 100644 --- a/doc.go +++ b/doc.go @@ -235,10 +235,10 @@ account when calculating image size. Paulo Coutinho provided support for static embedded fonts. Dan Meyers added support for embedded JavaScript. David Fish added a generic alias-replacement function to enable, among other things, table of contents functionality. Andy Bakun identified and corrected a problem in -which the internal catalogs were not sorted stably. d1ngd0 added encoding and -decoding functionality for templates, including images that are embedded in -templates; this allows templates to be stored independently of gofpdf. - +which the internal catalogs were not sorted stably. Paul Montag added encoding +and decoding functionality for templates, including images that are embedded in +templates; this allows templates to be stored independently of gofpdf. Paul +also added support for page boxes used in printing PDF documents. Roadmap diff --git a/fpdf.go b/fpdf.go index 43688dd..1e324b1 100644 --- a/fpdf.go +++ b/fpdf.go @@ -337,10 +337,11 @@ func (f *Fpdf) SetCellMargin(margin float64) { f.cMargin = margin } -// SetPageBox sets the page box for the current page, and any following pages. -// Allowable types are trim, trimbox, crop, cropbox, bleed, bleedbox, art and artbox -// box types are case insensitive. -func (f *Fpdf) SetPageBox(t string, pb PageBox) { +// SetPageBoxRec sets the page box for the current page, and any following +// pages. Allowable types are trim, trimbox, crop, cropbox, bleed, bleedbox, +// art and artbox box types are case insensitive. See SetPageBox() for a method +// that specifies the coordinates and extent of the page box individually. +func (f *Fpdf) SetPageBoxRec(t string, pb PageBox) { switch strings.ToLower(t) { case "trim": fallthrough @@ -376,6 +377,13 @@ func (f *Fpdf) SetPageBox(t string, pb PageBox) { f.defPageBoxes[t] = pb } +// SetPageBox sets the page box for the current page, and any following pages. +// Allowable types are trim, trimbox, crop, cropbox, bleed, bleedbox, art and +// artbox box types are case insensitive. +func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { + f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) +} + // SetFontLocation sets the location in the file system of the font and font // definition files. func (f *Fpdf) SetFontLocation(fontDirStr string) { diff --git a/fpdf_test.go b/fpdf_test.go index 62bae17..0e947ed 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -2194,10 +2194,6 @@ func ExampleNewGrid() { // Successfully generated pdf/Fpdf_Grid.pdf } -func pagebox(pdf *gofpdf.Fpdf, boxstr string, x, y, wd, ht float64) { - pdf.SetPageBox(boxstr, gofpdf.PageBox{gofpdf.SizeType{Wd: wd, Ht: ht}, gofpdf.PointType{X: x, Y: y}}) -} - // This example demonstrates the use of a page box func ExamplePageBox() { // pdfinfo (from http://www.xpdfreader.com) reports the following for this example: @@ -2224,7 +2220,7 @@ func ExamplePageBox() { boxmargin = 3 * fontsize ) pdf := gofpdf.New("P", "mm", "A4", "") // 210mm x 297mm - pagebox(pdf, "crop", boxmargin, boxmargin, wd-2*boxmargin, ht-2*boxmargin) + pdf.SetPageBox("crop", boxmargin, boxmargin, wd-2*boxmargin, ht-2*boxmargin) pdf.SetFont("Arial", "", pdf.UnitToPointConvert(fontsize)) pdf.AddPage() pdf.MoveTo(fontsize, fontsize) -- cgit v1.2.1-24-ge1ad