Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Watermark Only Some of a PDF's Pages
See more PDF Watermark Examples
Demonstrates choosing the pages to stamp. "pages" takes all (the default), first, last, odd, even, or a list of 1-based pages and ranges such as 1,3,5-9,12- where a trailing dash means "to the end". "excludePages" takes the same syntax and is applied afterwards, which is how you say "every page except the cover". The result reports the pages the watermark actually landed on.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
LOCAL loPdf2
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
? "pages in the document: " + STR(loPdf.NumPages)
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("type","text")
loJson.UpdateString("text","INTERNAL")
loJson.UpdateString("id","internal")
* Every page except the first.
loJson.UpdateString("pages","all")
loJson.UpdateString("excludePages","1")
lnSuccess = loPdf.Watermark("add",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "every page but the cover: " + loJsonOut.StringOf("pages")
* A list of pages and ranges, on a second copy of the document.
loPdf2 = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf2.LoadFile("qa_data/pdf/four_pages.pdf")
IF (lnSuccess = 0) THEN
? loPdf2.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
CANCEL
ENDIF
loJson2 = CreateObject('Chilkat.JsonObject')
loJson2.UpdateString("type","text")
loJson2.UpdateString("text","APPENDIX")
loJson2.UpdateString("id","appendix")
loJson2.UpdateString("pages","2,4-")
lnSuccess = loPdf2.Watermark("add",loJson2,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf2.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
RELEASE loJson2
CANCEL
ENDIF
? "page 2 and 4 onwards: " + loJsonOut.StringOf("pages")
lnSuccess = loPdf.WriteFile("qa_output/four_pages_internal.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
RELEASE loJson2
CANCEL
ENDIF
* Sample output:
* pages in the document: 4
* every page but the cover: 2-4
* page 2 and 4 onwards: 2,4
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loPdf2
RELEASE loJson2