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

How a PDF Watermark Is Stored: artifact, annotation, layer or content

See more PDF Watermark Examples

Demonstrates the approach member, which decides how the watermark is stored and therefore what can be done with it afterwards. artifact (the default) is marked content that viewers draw, text extraction leaves out and Chilkat can remove later. annotation is a Watermark annotation, always on top, and the only approach allowed on a signed PDF while PreserveSignatures is true. layer is an optional-content layer the viewer can hide and that can be made print-only. content draws straight into the page with no marker: visible everywhere and the tamper-resistant choice, but by design it can never be listed or removed again.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loJson
LOCAL loJsonOut
LOCAL loFilter
LOCAL loPdf
LOCAL loPdf2
LOCAL loPdf3
LOCAL loPdf4

lnSuccess = 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 two_page_memo.pdf

loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
loFilter = CreateObject('Chilkat.JsonObject')

*  The same watermark stored four different ways, each in its own copy of the document.
loPdf = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf.LoadFile("qa_data/pdf/two_page_memo.pdf")
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    CANCEL
ENDIF

loJson.UpdateString("type","text")
loJson.UpdateString("text","DRAFT")
loJson.UpdateString("id","draft")
loJson.UpdateString("approach","artifact")
lnSuccess = loPdf.Watermark("add",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    CANCEL
ENDIF

*  detect answers whether anything matching the filter is in the document.  Finding nothing is
*  still success: "found" is simply false.
loFilter.UpdateString("id","draft")
lnSuccess = loPdf.Watermark("detect",loFilter,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    CANCEL
ENDIF

? "artifact: found = " + STR(loJsonOut.BoolOf("found"))

*  An annotation: always drawn on top, and the one approach a signed PDF accepts.
loPdf2 = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf2.LoadFile("qa_data/pdf/two_page_memo.pdf")
IF (lnSuccess = 0) THEN
    ? loPdf2.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    CANCEL
ENDIF

loJson.UpdateString("approach","annotation")
lnSuccess = loPdf2.Watermark("add",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf2.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    CANCEL
ENDIF

lnSuccess = loPdf2.Watermark("detect",loFilter,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf2.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    CANCEL
ENDIF

? "annotation: found = " + STR(loJsonOut.BoolOf("found"))

*  A layer, which the viewer's layers panel can switch off.
loPdf3 = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf3.LoadFile("qa_data/pdf/two_page_memo.pdf")
IF (lnSuccess = 0) THEN
    ? loPdf3.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    RELEASE loPdf3
    CANCEL
ENDIF

loJson.UpdateString("approach","layer")
loJson.UpdateString("layer.name","Draft marking")
lnSuccess = loPdf3.Watermark("add",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf3.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    RELEASE loPdf3
    CANCEL
ENDIF

lnSuccess = loPdf3.Watermark("detect",loFilter,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf3.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    RELEASE loPdf3
    CANCEL
ENDIF

? "layer: found = " + STR(loJsonOut.BoolOf("found"))

*  Drawn into the page content with no marker.  There is nothing to find afterwards, which is the
*  point of it: it cannot be stripped out by a tool that removes watermarks.
loPdf4 = CreateObject('Chilkat.Pdf')
lnSuccess = loPdf4.LoadFile("qa_data/pdf/two_page_memo.pdf")
IF (lnSuccess = 0) THEN
    ? loPdf4.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    RELEASE loPdf3
    RELEASE loPdf4
    CANCEL
ENDIF

loJson.UpdateString("approach","content")
lnSuccess = loPdf4.Watermark("add",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf4.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    RELEASE loPdf3
    RELEASE loPdf4
    CANCEL
ENDIF

lnSuccess = loPdf4.Watermark("detect",loFilter,loJsonOut)
IF (lnSuccess = 0) THEN
    ? loPdf4.LastErrorText
    RELEASE loJson
    RELEASE loJsonOut
    RELEASE loFilter
    RELEASE loPdf
    RELEASE loPdf2
    RELEASE loPdf3
    RELEASE loPdf4
    CANCEL
ENDIF

? "content: found = " + STR(loJsonOut.BoolOf("found"))

*  Sample output:

*  artifact: found = True
*  annotation: found = True
*  layer: found = True
*  content: found = False

RELEASE loJson
RELEASE loJsonOut
RELEASE loFilter
RELEASE loPdf
RELEASE loPdf2
RELEASE loPdf3
RELEASE loPdf4