diff options
| author | Kurt <kurt.w.jung@gmail.com> | 2019-04-10 08:06:56 -0400 | 
|---|---|---|
| committer | Kurt <kurt.w.jung@gmail.com> | 2019-04-10 08:06:56 -0400 | 
| commit | adea43f9f1e4324cde55328c74e0e1a7af9aaf73 (patch) | |
| tree | 6911238e7df9976ec0fe32c96a5eaa2549bc5e86 | |
| parent | 83024250a9829a15db59ff414a36984300c98771 (diff) | |
Add watermark example
| -rw-r--r-- | fpdf.go | 5 | ||||
| -rw-r--r-- | fpdf_test.go | 41 | 
2 files changed, 46 insertions, 0 deletions
| @@ -430,6 +430,11 @@ func (f *Fpdf) SetHeaderFuncMode(fnc func(), homeMode bool) {  // headers. fnc will typically be a closure that has access to the Fpdf  // instance and other document generation variables.  // +// A header is a convenient place to put background content that repeats on +// each page such as a watermark. When this is done, remember to reset the X +// and Y values so the normal content begins where expected. Including a +// watermark on each page is demonstrated in the example for TransformRotate. +//  // This method is demonstrated in the example for AddPage().  func (f *Fpdf) SetHeaderFunc(fnc func()) {  	f.headerFnc = fnc diff --git a/fpdf_test.go b/fpdf_test.go index 53609bf..d894607 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -2476,3 +2476,44 @@ func ExampleFpdf_SetFillColor() {  	// Output:  	// Successfully generated pdf/Fpdf_SetFillColor.pdf  } + +// ExampleFpdf_TransformRotate demonstrates how to rotate text within a header +// to make a watermark that appears on each page. +func ExampleFpdf_TransformRotate() { + +	loremStr := lorem() + "\n\n" +	pdf := gofpdf.New("P", "mm", "A4", "") +	margin := 25.0 +	pdf.SetMargins(margin, margin, margin) + +	fontHt := 13.0 +	lineHt := pdf.PointToUnitConvert(fontHt) +	markFontHt := 50.0 +	markLineHt := pdf.PointToUnitConvert(markFontHt) +	markY := (297.0 - markLineHt) / 2.0 +	ctrX := 210.0 / 2.0 +	ctrY := 297.0 / 2.0 + +	pdf.SetHeaderFunc(func() { +		pdf.SetFont("Arial", "B", markFontHt) +		pdf.SetTextColor(206, 216, 232) +		pdf.SetXY(margin, markY) +		pdf.TransformBegin() +		pdf.TransformRotate(45, ctrX, ctrY) +		pdf.CellFormat(0, markLineHt, "W A T E R M A R K   D E M O", "", 0, "C", false, 0, "") +		pdf.TransformEnd() +		pdf.SetXY(margin, margin) +	}) + +	pdf.AddPage() +	pdf.SetFont("Arial", "", 8) +	for j := 0; j < 25; j++ { +		pdf.MultiCell(0, lineHt, loremStr, "", "L", false) +	} + +	fileStr := example.Filename("Fpdf_RotateText") +	err := pdf.OutputFileAndClose(fileStr) +	example.Summary(err, fileStr) +	// Output: +	// Successfully generated pdf/Fpdf_RotateText.pdf +} | 
