summaryrefslogtreecommitdiff
path: root/fpdf_test.go
diff options
context:
space:
mode:
authorKurt <kurt.w.jung@gmail.com>2018-11-10 14:08:52 -0500
committerKurt <kurt.w.jung@gmail.com>2018-11-10 14:08:52 -0500
commit41627bb3061b250ed757f243df74918986177ec9 (patch)
treeb9d18ac96c46ee6bd7a904ec851f0190e2cce14d /fpdf_test.go
parent13c78403a35a19e3943791af9435411c401ab446 (diff)
parente86946141846a08ffb531a1f2c9625282cbc335a (diff)
Merge branch 'd1ngd0-ftr/boxes'
Diffstat (limited to 'fpdf_test.go')
-rw-r--r--fpdf_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/fpdf_test.go b/fpdf_test.go
index 68a26ad..62bae17 100644
--- a/fpdf_test.go
+++ b/fpdf_test.go
@@ -2193,3 +2193,47 @@ func ExampleNewGrid() {
// Output:
// 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:
+ // ~ pdfinfo -box pdf/Fpdf_PageBox.pdf
+ // Producer: FPDF 1.7
+ // CreationDate: Sat Jan 1 00:00:00 2000
+ // Tagged: no
+ // Form: none
+ // Pages: 1
+ // Encrypted: no
+ // Page size: 493.23 x 739.85 pts (rotated 0 degrees)
+ // MediaBox: 0.00 0.00 595.28 841.89
+ // CropBox: 51.02 51.02 544.25 790.87
+ // BleedBox: 51.02 51.02 544.25 790.87
+ // TrimBox: 51.02 51.02 544.25 790.87
+ // ArtBox: 51.02 51.02 544.25 790.87
+ // File size: 1053 bytes
+ // Optimized: no
+ // PDF version: 1.3
+ const (
+ wd = 210
+ ht = 297
+ fontsize = 6
+ boxmargin = 3 * fontsize
+ )
+ pdf := gofpdf.New("P", "mm", "A4", "") // 210mm x 297mm
+ pagebox(pdf, "crop", boxmargin, boxmargin, wd-2*boxmargin, ht-2*boxmargin)
+ pdf.SetFont("Arial", "", pdf.UnitToPointConvert(fontsize))
+ pdf.AddPage()
+ pdf.MoveTo(fontsize, fontsize)
+ pdf.Write(fontsize, "This will be cropped from printed output")
+ pdf.MoveTo(boxmargin+fontsize, boxmargin+fontsize)
+ pdf.Write(fontsize, "This will be displayed in cropped output")
+ fileStr := example.Filename("Fpdf_PageBox")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated pdf/Fpdf_PageBox.pdf
+}