DataFlex Requires Chilkat v11.7.0+
DataFlex
Find Out Whether a PDF Has a Watermark
See more PDF Watermark Examples
Demonstrates detect, which answers yes or no, and list, which enumerates what is there. Both recognize the watermarks Chilkat writes and the standard forms other tools write: Watermark annotations from any producer, marked content tagged as a Watermark or Background artifact, Acrobat watermarks and backgrounds, and optional-content layers whose name says watermark. Acrobat headers and footers are not watermarks and are ignored. A watermark from another producer has no id of its own, so Chilkat assigns one (ext1, ext2, ...) that stays valid until the PDF is changed, which is what makes a list followed by a remove by id work. Properties that cannot be read back are left out rather than guessed.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPdf
Variant vFilter
Handle hoFilter
Variant vJsonOut
Handle hoJsonOut
Integer i
Integer iCount_i
Variant vBySource
Handle hoBySource
String sTemp1
Integer iTemp1
Boolean bTemp1
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 acrobat_two_watermarks.pdf
Get Create (RefClass(cComChilkatPdf)) To hoPdf
If (Not(IsComObjectCreated(hoPdf))) Begin
Send CreateComObject of hoPdf
End
Get ComLoadFile Of hoPdf "qa_data/pdf/acrobat_two_watermarks.pdf" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
// An empty filter means every watermark in the document.
Get Create (RefClass(cComChilkatJsonObject)) To hoFilter
If (Not(IsComObjectCreated(hoFilter))) Begin
Send CreateComObject of hoFilter
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
If (Not(IsComObjectCreated(hoJsonOut))) Begin
Send CreateComObject of hoJsonOut
End
Get pvComObject of hoFilter to vFilter
Get pvComObject of hoJsonOut to vJsonOut
Get ComWatermark Of hoPdf "detect" vFilter vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComBoolOf Of hoJsonOut "found" To bTemp1
Get ComIntOf Of hoJsonOut "count" To iTemp1
Showln "found: " bTemp1 " count: " iTemp1
Get pvComObject of hoFilter to vFilter
Get pvComObject of hoJsonOut to vJsonOut
Get ComWatermark Of hoPdf "list" vFilter vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Move 0 To i
Get ComSizeOfArray Of hoJsonOut "watermarks" To iCount_i
While (i < iCount_i)
Set ComI Of hoJsonOut To i
Get ComStringOf Of hoJsonOut "watermarks[i].id" To sTemp1
Showln "id: " sTemp1
Get ComStringOf Of hoJsonOut "watermarks[i].source" To sTemp1
Showln " source: " sTemp1
Get ComStringOf Of hoJsonOut "watermarks[i].approach" To sTemp1
Showln " approach: " sTemp1
Get ComStringOf Of hoJsonOut "watermarks[i].type" To sTemp1
Showln " type: " sTemp1
Get ComStringOf Of hoJsonOut "watermarks[i].text" To sTemp1
Showln " text: " sTemp1
Get ComStringOf Of hoJsonOut "watermarks[i].pages" To sTemp1
Showln " pages: " sTemp1
Get ComStringOf Of hoJsonOut "watermarks[i].zOrder" To sTemp1
Showln " zOrder: " sTemp1
Get ComBoolOf Of hoJsonOut "watermarks[i].removable" To bTemp1
Showln " removable: " bTemp1
Move (i + 1) To i
Loop
// The filter narrows what is reported: by producer (chilkat, acrobat or other), by approach, by
// pages, by an exact id or label, or by text with textContains.
Get Create (RefClass(cComChilkatJsonObject)) To hoBySource
If (Not(IsComObjectCreated(hoBySource))) Begin
Send CreateComObject of hoBySource
End
Get ComUpdateString Of hoBySource "source" "acrobat" To iSuccess
Get pvComObject of hoBySource to vBySource
Get pvComObject of hoJsonOut to vJsonOut
Get ComWatermark Of hoPdf "detect" vBySource vJsonOut To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPdf To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComIntOf Of hoJsonOut "count" To iTemp1
Showln "made by Acrobat: " iTemp1
// Sample output:
// found: True count: 2
// id: ext1
// source: acrobat
// approach: artifact
// type: image
// text:
// pages: 1
// zOrder: front
// removable: True
// id: ext2
// source: acrobat
// approach: artifact
// type: text
// text: sample
// pages: 1
// zOrder: front
// removable: True
// made by Acrobat: 2
End_Procedure