Delphi DLL Requires Chilkat v11.7.0+
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
pdf: HCkPdf;
filter: HCkJsonObject;
jsonOut: HCkJsonObject;
i: Integer;
count_i: Integer;
bySource: HCkJsonObject;
begin
success := False;
// 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
pdf := CkPdf_Create();
success := CkPdf_LoadFile(pdf,'qa_data/pdf/acrobat_two_watermarks.pdf');
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
// An empty filter means every watermark in the document.
filter := CkJsonObject_Create();
jsonOut := CkJsonObject_Create();
success := CkPdf_Watermark(pdf,'detect',filter,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
Memo1.Lines.Add('found: ' + IntToStr(Ord(CkJsonObject_BoolOf(jsonOut,'found'))) + ' count: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'count')));
success := CkPdf_Watermark(pdf,'list',filter,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonOut,'watermarks');
while i < count_i do
begin
CkJsonObject_putI(jsonOut,i);
Memo1.Lines.Add('id: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].id'));
Memo1.Lines.Add(' source: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].source'));
Memo1.Lines.Add(' approach: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].approach'));
Memo1.Lines.Add(' type: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].type'));
Memo1.Lines.Add(' text: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].text'));
Memo1.Lines.Add(' pages: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].pages'));
Memo1.Lines.Add(' zOrder: ' + CkJsonObject__stringOf(jsonOut,'watermarks[i].zOrder'));
Memo1.Lines.Add(' removable: ' + IntToStr(Ord(CkJsonObject_BoolOf(jsonOut,'watermarks[i].removable'))));
i := i + 1;
end;
// 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.
bySource := CkJsonObject_Create();
CkJsonObject_UpdateString(bySource,'source','acrobat');
success := CkPdf_Watermark(pdf,'detect',bySource,jsonOut);
if (success = False) then
begin
Memo1.Lines.Add(CkPdf__lastErrorText(pdf));
Exit;
end;
Memo1.Lines.Add('made by Acrobat: ' + IntToStr(CkJsonObject_IntOf(jsonOut,'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
CkPdf_Dispose(pdf);
CkJsonObject_Dispose(filter);
CkJsonObject_Dispose(jsonOut);
CkJsonObject_Dispose(bySource);