Add text, image or PDF-page watermarks to a PDF's pages with full control over placement, styling and how they are stored; then detect, list and remove watermarks — Chilkat's own, Acrobat's, and the standard forms other tools write.
Filter; an empty filter is refused unless "all": true
removed count
Finding nothing is still success: detect returns true with found false, and remove returns true with removed 0. Changes are made in memory and written by WriteFile or WriteBd.
Quick start
A diagonal CONFIDENTIAL across every page, with an id so that it can be removed later. Only type and its content are required; everything else has a default.
Chilkat.Pdf pdf = new Chilkat.Pdf();
pdf.LoadFile("report.pdf");
Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
jsonIn.UpdateString("type", "text");
jsonIn.UpdateString("text", "CONFIDENTIAL");
jsonIn.UpdateString("id", "conf");
jsonIn.UpdateString("color", "#C00000");
jsonIn.UpdateNumber("opacity", "0.25");
jsonIn.UpdateString("rotation", "diagonal");
jsonIn.UpdateString("scale.fit", "page");
jsonIn.UpdateInt("scale.fitPercent", 80);
if (pdf.Watermark("add", jsonIn, jsonOut)) {
pdf.WriteFile("report_confidential.pdf");
}
The approach member selects how an added watermark is stored, which decides whether it can be found and removed later and how viewers treat it. Default: artifact.
approach
Stored as
Visible in
Removable later
Text extractable
artifact
Marked content tagged as a Watermark or Background artifact
All viewers
yes
No (artifacts are skipped)
annotation
A Watermark annotation
Most viewers; always on top
yes
No
layer
An optional-content layer
All viewers; can be hidden or made print-only
yes
Depends on the extractor
content
Drawn into the page content, unmarked
All viewers
no (by design)
Yes
For every approach except content, Chilkat stores a private identifier with the watermark; that is what lets list and remove target it later. content watermarks are deliberately untagged: they are the tamper-resistant choice.
add: general options
Members are written as dotted paths, as used with the JsonObject update methods (scale.fit is the member fit of the object scale).
Member
Values (default in bold)
Description
approach
content, annotation, artifact, layer
See above.
id
string (generated)
Returned in jsonOut; used by list and remove. An id already present in the document is refused. Not stored for content.
label
string (none)
A free-form description stored with the watermark and returned by list.
zOrder
front, back
In front of or behind the existing content. Ignored for annotation, which is always in front.
pages
all, first, last, odd, even, or a range list such as 1,3,5-9,12-
The pages to stamp.
excludePages
range list (none)
Applied after pages.
units
pt, in, mm, cm
The units of the image size, wrap width, padding, margins, offsets, maximum sizes and tile spacing. Font size, outline width and border width are always in points.
pageBox
crop, media
The page box placement is measured against.
followPageRotation
true, false
Keeps the watermark upright for the reader on pages with a /Rotate setting.
jsonIn: odd pages only, except the cover, in millimetres
{
"type": "text", "text": "DRAFT",
"zOrder": "back",
"label": "Draft banner, added by the review tool"
}
jsonOut
{ "id": "wm2", "pages": "1-12" }
add: content (type = text, image, pdfPage)
Member
Values (default in bold)
Description
type
text, image, pdfPage
Required. Any type can be stored with any approach. (barcode is reserved for a later release; an existing barcode or QR image can be added as an image.)
text
string
Required for text. \n breaks lines. Placeholders are replaced per page: {page}, {pages}, {date:FORMAT}, {filename}; {{ for a literal brace.
image.path / image.base64
file path, or base64 data
Required for image. JPEG and PNG; PNG transparency is kept (interlaced PNG is not supported).
image.width, image.height
number (natural size)
Give one to keep the aspect ratio.
pdf.path / pdf.base64
file path, or base64 data
Required for pdfPage: letterheads, cover overlays, vector logos saved as PDF.
pdf.password
string (none)
For an encrypted source PDF.
pdf.page
1, a page number, or match
match maps source page n onto target page n, cycling if the source is shorter.
The {date:FORMAT} placeholder
The current local date and time, formatted with yyyy or yy (year), M/MM (month), d/dd (day), H/HH (hour, 24-hour), h/hh (hour, 12-hour), m/mm (minute), s/ss (second) and tt (AM/PM); any other character is copied, and there are no month or weekday names. {date} alone means {date:yyyy-MM-dd}.
The three operations share one filter in jsonIn; an empty jsonIn means every watermark in the document. They recognize Chilkat's own watermarks and the standard forms other tools write:
anything Chilkat added with an approach other than content;
Watermark annotations from any producer;
marked content tagged as an artifact of subtype Watermark or Background;
Acrobat watermarks and backgrounds (Acrobat headers and footers are not watermarks and are ignored);
optional-content layers whose name contains "watermark".
Member
Values (default in bold)
Description
pages
all or a range list
Same syntax as add; restricts which pages are examined.
approach
any, or one approach keyword
source
any, chilkat, acrobat, other
Who produced it.
id
string
Exact match on the watermark's id (a Chilkat id, or an assigned extN id).
label
string
Exact match on a Chilkat label.
textContains
string
Case-insensitive match on the watermark's text.
heuristic
false, true
Reserved for untagged page content that looks like a watermark; accepted but not implemented in this release.
all
false, true
remove only: required to remove with an otherwise empty filter.
The watermark's id. Watermarks from other producers have none, so Chilkat assigns a read-only one (ext1, ext2, ...) that stays valid until the PDF is changed, so that a list followed by a remove by id works.
The watermark's properties. Properties that cannot be read back (the opacity of a scanned-in watermark, for example) are omitted rather than guessed.
removable
Whether remove can delete it.
pages
The pages it appears on, such as 1-12 or 1,3,5.
Removal
annotation: the annotation is deleted.
artifact: the marked content, and any form XObject used only by it, are deleted.
layer: the layer's content is deleted, and the layer itself once nothing else uses it.
content: never removable.
jsonIn: strip every Acrobat watermark
{ "source": "acrobat" }
jsonOut (remove)
{ "removed": 1 }
jsonIn: remove everything
{ "all": true }
jsonOut (remove)
{ "removed": 3 }
// Find and strip every Acrobat watermark
Chilkat.Pdf pdf = new Chilkat.Pdf();
pdf.LoadFile("in.pdf");
Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
jsonIn.UpdateString("source", "acrobat");
if (pdf.Watermark("remove", jsonIn, jsonOut) && jsonOut.IntOf("removed") > 0) {
pdf.WriteFile("clean.pdf");
}
Signed and encrypted PDFs
Signed PDFs. With the PreserveSignatures property true (the default), only the annotation approach can be added, and nothing can be removed, because any other change to the page content would invalidate the signatures. Set it to false to allow such changes and accept that the signatures become invalid.
Encrypted PDFs. The PDF must have been opened (UserPassword / OwnerPassword), and adding or removing requires owner rights or the modify permission (see Protection). detect and list only read.
Watermarks are excluded from ExtractText output by its artifacts filter, and Optimize removes the empty "Watermark" layer Acrobat leaves behind after removing a watermark.
Privacy Statement. Copyright Chilkat Software, Inc. All rights reserved. (Regarding the usage of the Android logo) Portions of this page are reproduced from work created and shared by Google and used according to terms described in the
Creative Commons 3.0 Attribution License.
Send feedback to info@chilkatsoft.com Software APIs, modules, components, and libraries for Windows, Linux, MacOS, iOS, Android™, Alpine Linux, MinGW, ...