diff options
Diffstat (limited to 'fpdf_test.go')
-rw-r--r-- | fpdf_test.go | 44 |
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 +} |