VBScript Requires Chilkat v11.7.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 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 acrobat_two_watermarks.pdf
set pdf = CreateObject("Chilkat.Pdf")
success = pdf.LoadFile("qa_data/pdf/acrobat_two_watermarks.pdf")
If (success = 0) Then
outFile.WriteLine(pdf.LastErrorText)
WScript.Quit
End If
' An empty filter means every watermark in the document.
set filter = CreateObject("Chilkat.JsonObject")
set jsonOut = CreateObject("Chilkat.JsonObject")
success = pdf.Watermark("detect",filter,jsonOut)
If (success = 0) Then
outFile.WriteLine(pdf.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("found: " & jsonOut.BoolOf("found") & " count: " & jsonOut.IntOf("count"))
success = pdf.Watermark("list",filter,jsonOut)
If (success = 0) Then
outFile.WriteLine(pdf.LastErrorText)
WScript.Quit
End If
i = 0
count_i = jsonOut.SizeOfArray("watermarks")
Do While i < count_i
jsonOut.I = i
outFile.WriteLine("id: " & jsonOut.StringOf("watermarks[i].id"))
outFile.WriteLine(" source: " & jsonOut.StringOf("watermarks[i].source"))
outFile.WriteLine(" approach: " & jsonOut.StringOf("watermarks[i].approach"))
outFile.WriteLine(" type: " & jsonOut.StringOf("watermarks[i].type"))
outFile.WriteLine(" text: " & jsonOut.StringOf("watermarks[i].text"))
outFile.WriteLine(" pages: " & jsonOut.StringOf("watermarks[i].pages"))
outFile.WriteLine(" zOrder: " & jsonOut.StringOf("watermarks[i].zOrder"))
outFile.WriteLine(" removable: " & jsonOut.BoolOf("watermarks[i].removable"))
i = i + 1
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.
set bySource = CreateObject("Chilkat.JsonObject")
success = bySource.UpdateString("source","acrobat")
success = pdf.Watermark("detect",bySource,jsonOut)
If (success = 0) Then
outFile.WriteLine(pdf.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("made by Acrobat: " & jsonOut.IntOf("count"))
' 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
outFile.Close