Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Place and Size a PDF Watermark: Alignment, Margins and Fitting
See more PDF Watermark Examples
Demonstrates where the stamp goes and how large it is drawn. position.align picks one of nine spots, position.margin insets it from the page edges, and position.offsetX and offsetY nudge it from there. For the size, scale.factor multiplies the natural size, scale.fit fits the rotated stamp inside the margin box (none, page, width or height) with scale.fitPercent saying how much of that box to fill, and scale.maxWidth and maxHeight cap the result. The units member applies to all of the measurements except font size, which is always in points.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
LOCAL loJson2
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* The PDF used in this example is available at four_pages.pdf
loPdf = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf.LoadFile("qa_data/pdf/four_pages.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
CANCEL
ENDIF
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
* A banner across the top, inset three quarters of an inch, filling 60% of the width.
loJson.UpdateString("type","text")
loJson.UpdateString("text","REVIEW COPY")
loJson.UpdateString("id","banner")
loJson.UpdateString("units","in")
loJson.UpdateString("position.align","top")
loJson.UpdateNumber("position.margin","0.75")
loJson.UpdateString("scale.fit","width")
loJson.UpdateNumber("scale.fitPercent","60")
loJson.UpdateString("color","#1F4E79")
lnSuccess = loPdf.Watermark("add",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "banner pages: " + loJsonOut.StringOf("pages")
* A second stamp in the bottom-left corner, nudged a quarter inch to the right and up, with its
* size capped rather than fitted.
loJson2 = CreateObject('Chilkat.JsonObject')
loJson2.UpdateString("type","text")
loJson2.UpdateString("text","Not for distribution")
loJson2.UpdateString("id","footnote")
loJson2.UpdateString("units","in")
loJson2.UpdateString("position.align","bottomLeft")
loJson2.UpdateNumber("position.margin","0.5")
loJson2.UpdateNumber("position.offsetX","0.25")
loJson2.UpdateNumber("position.offsetY","-0.25")
loJson2.UpdateNumber("font.size","9")
loJson2.UpdateNumber("scale.maxWidth","3.0")
lnSuccess = loPdf.Watermark("add",loJson2,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loJson2
CANCEL
ENDIF
? "footnote pages: " + loJsonOut.StringOf("pages")
* Each call adds one watermark, so a banner plus a note is two calls.
lnSuccess = loPdf.WriteFile("qa_output/four_pages_placed.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loJson2
CANCEL
ENDIF
* Sample output:
* banner pages: 1-4
* footnote pages: 1-4
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loJson2