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

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Pdf
oleobject loo_Filter
oleobject loo_JsonOut
long i
long li_Count_i
oleobject loo_BySource

li_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

loo_Pdf = create oleobject
li_rc = loo_Pdf.ConnectToNewObject("Chilkat.Pdf")
if li_rc < 0 then
    destroy loo_Pdf
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Pdf.LoadFile("qa_data/pdf/acrobat_two_watermarks.pdf")
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    return
end if

//  An empty filter means every watermark in the document.
loo_Filter = create oleobject
li_rc = loo_Filter.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonOut = create oleobject
li_rc = loo_JsonOut.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_Pdf.Watermark("detect",loo_Filter,loo_JsonOut)
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_Filter
    destroy loo_JsonOut
    return
end if

Write-Debug "found: " + string(loo_JsonOut.BoolOf("found")) + " count: " + string(loo_JsonOut.IntOf("count"))

li_Success = loo_Pdf.Watermark("list",loo_Filter,loo_JsonOut)
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_Filter
    destroy loo_JsonOut
    return
end if

i = 0
li_Count_i = loo_JsonOut.SizeOfArray("watermarks")
do while i < li_Count_i
    loo_JsonOut.I = i
    Write-Debug "id: " + loo_JsonOut.StringOf("watermarks[i].id")
    Write-Debug "   source:    " + loo_JsonOut.StringOf("watermarks[i].source")
    Write-Debug "   approach:  " + loo_JsonOut.StringOf("watermarks[i].approach")
    Write-Debug "   type:      " + loo_JsonOut.StringOf("watermarks[i].type")
    Write-Debug "   text:      " + loo_JsonOut.StringOf("watermarks[i].text")
    Write-Debug "   pages:     " + loo_JsonOut.StringOf("watermarks[i].pages")
    Write-Debug "   zOrder:    " + loo_JsonOut.StringOf("watermarks[i].zOrder")
    Write-Debug "   removable: " + string(loo_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.
loo_BySource = create oleobject
li_rc = loo_BySource.ConnectToNewObject("Chilkat.JsonObject")

loo_BySource.UpdateString("source","acrobat")
li_Success = loo_Pdf.Watermark("detect",loo_BySource,loo_JsonOut)
if li_Success = 0 then
    Write-Debug loo_Pdf.LastErrorText
    destroy loo_Pdf
    destroy loo_Filter
    destroy loo_JsonOut
    destroy loo_BySource
    return
end if

Write-Debug "made by Acrobat: " + string(loo_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


destroy loo_Pdf
destroy loo_Filter
destroy loo_JsonOut
destroy loo_BySource