Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.7.0+

A PDF Watermark That Only Appears When Printed

See more PDF Watermark Examples

Demonstrates a watermark that is invisible on screen and appears on paper, which is what a "printed copies are uncontrolled" marking needs. Two approaches can do it: an optional-content layer with layer.view off and layer.print on, which also gives the reader an entry in the layers panel of the viewer (layer.locked stops them switching it), and a Watermark annotation with annotation.view false and annotation.print true. annotation.fixedPrint keeps the printed size and position the same whatever paper it goes on.

Chilkat AutoIt Downloads

AutoIt
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 two_page_memo.pdf

$oPdf = ObjCreate("Chilkat.Pdf")
$bSuccess = $oPdf.LoadFile("qa_data/pdf/two_page_memo.pdf")
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("type","text")
$oJson.UpdateString("text","UNCONTROLLED WHEN PRINTED")
$oJson.UpdateString("id","printonly")

;  As a layer: off on screen, on when printing, and locked so the reader cannot switch it on.
$oJson.UpdateString("approach","layer")
$oJson.UpdateString("layer.name","Print marking")
$oJson.UpdateString("layer.view","off")
$oJson.UpdateString("layer.print","on")
$oJson.UpdateBool("layer.locked",True)

$oJson.UpdateString("rotation","diagonal")
$oJson.UpdateString("scale.fit","page")
$oJson.UpdateNumber("scale.fitPercent","70")
$oJson.UpdateNumber("opacity","0.3")

$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oPdf.Watermark("add",$oJson,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("layer id: " & $oJsonOut.StringOf("id") & " pages: " & $oJsonOut.StringOf("pages") & @CRLF)

$bSuccess = $oPdf.WriteFile("qa_output/memo_print_only.pdf")
If ($bSuccess = False) Then
    ConsoleWrite($oPdf.LastErrorText & @CRLF)
    Exit
EndIf

;  The same thing as an annotation instead.
$oPdf2 = ObjCreate("Chilkat.Pdf")
$bSuccess = $oPdf2.LoadFile("qa_data/pdf/two_page_memo.pdf")
If ($bSuccess = False) Then
    ConsoleWrite($oPdf2.LastErrorText & @CRLF)
    Exit
EndIf

$oJson2 = ObjCreate("Chilkat.JsonObject")
$oJson2.UpdateString("type","text")
$oJson2.UpdateString("text","UNCONTROLLED WHEN PRINTED")
$oJson2.UpdateString("id","printonly2")
$oJson2.UpdateString("approach","annotation")
$oJson2.UpdateBool("annotation.view",False)
$oJson2.UpdateBool("annotation.print",True)
$oJson2.UpdateBool("annotation.fixedPrint",True)
$oJson2.UpdateString("rotation","diagonal")
$bSuccess = $oPdf2.Watermark("add",$oJson2,$oJsonOut)
If ($bSuccess = False) Then
    ConsoleWrite($oPdf2.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("annotation id: " & $oJsonOut.StringOf("id") & @CRLF)

;  Sample output:

;  layer id: printonly pages: 1-2
;  annotation id: printonly2