AutoIt Requires Chilkat v11.7.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; 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
$oPdf = ObjCreate("Chilkat.Pdf")
$bSuccess = $oPdf.LoadFile("qa_data/pdf/four_pages.pdf")
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("pages in the document: " & $oPdf.NumPages & @CRLF)
$oJson = ObjCreate("Chilkat.JsonObject")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("type","text")
$oJson.UpdateString("text","INTERNAL")
$oJson.UpdateString("id","internal")
; Every page except the first.
$oJson.UpdateString("pages","all")
$oJson.UpdateString("excludePages","1")
$bSuccess = $oPdf.Watermark("add",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("every page but the cover: " & $oJsonOut.StringOf("pages") & @CRLF)
; A list of pages and ranges, on a second copy of the document.
$oPdf2 = ObjCreate("Chilkat.Pdf")
$bSuccess = $oPdf2.LoadFile("qa_data/pdf/four_pages.pdf")
If ($bSuccess = False) Then
ConsoleWrite($oPdf2.LastErrorText & @CRLF)
Exit
EndIf
$oJson2 = ObjCreate("Chilkat.JsonObject")
$oJson2.UpdateString("type","text")
$oJson2.UpdateString("text","APPENDIX")
$oJson2.UpdateString("id","appendix")
$oJson2.UpdateString("pages","2,4-")
$bSuccess = $oPdf2.Watermark("add",$oJson2,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oPdf2.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("page 2 and 4 onwards: " & $oJsonOut.StringOf("pages") & @CRLF)
$bSuccess = $oPdf.WriteFile("qa_output/four_pages_internal.pdf")
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
; Sample output:
; pages in the document: 4
; every page but the cover: 2-4
; page 2 and 4 onwards: 2,4