DataFlex Requires Chilkat v11.7.0+
DataFlex
Tile a Watermark Across a PDF Page
See more PDF Watermark Examples
Demonstrates a tiled watermark, which repeats the stamp over the whole page instead of placing it once. Tiling overrides position.align; tile.spacingX and spacingY set the gaps, and tile.stagger offsets alternate rows by half a tile so the pattern does not line up in columns. A faint tiled stamp carrying the name or address is the usual way to mark a document so that a leaked copy can be traced back, and zOrder back keeps it behind the text where it does not hinder reading.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vJson
Handle hoJson
Variant vJsonOut
Handle hoJsonOut
String sTemp1
String sTemp2
Move False To iSuccess
// 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 long_report.pdf
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/long_report.pdf" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "type" "text" To iSuccess
// {date:FORMAT} is replaced per page when the watermark is added. The other placeholders are
// {page}, {pages} and {filename}; {{ gives a literal brace.
Get ComUpdateString Of hoJson "text" "jdoe@example.com {date:yyyy-MM-dd}" To iSuccess
Get ComUpdateString Of hoJson "id" "trace" To iSuccess
Get ComUpdateString Of hoJson "zOrder" "back" To iSuccess
Get ComUpdateNumber Of hoJson "font.size" "14" To iSuccess
Get ComUpdateNumber Of hoJson "opacity" "0.15" To iSuccess
Get ComUpdateNumber Of hoJson "rotation" "30" To iSuccess
Get ComUpdateBool Of hoJson "tile.enabled" True To iSuccess
Get ComUpdateNumber Of hoJson "tile.spacingX" "60" To iSuccess
Get ComUpdateNumber Of hoJson "tile.spacingY" "80" To iSuccess
Get ComUpdateBool Of hoJson "tile.stagger" True To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoJsonOut to vJsonOut
Get ComWatermark Of hoPdf "add" vJson vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStringOf Of hoJsonOut "id" To sTemp1
Get ComStringOf Of hoJsonOut "pages" To sTemp2
Showln "id: " sTemp1 " pages: " sTemp2
Get ComWriteFile Of hoPdf "qa_output/report_traced.pdf" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
// Sample output:
// id: trace pages: 1-3
End_Procedure