Class PdfWatermarker
Lays a visible Watermark over the pages of a PDF document, and removes it again. The same Watermark marks a picture through ApplyWatermark(Watermark), with the same look.
public static class PdfWatermarker
- Inheritance
-
PdfWatermarker
- Inherited Members
Examples
using LMKit.Data;
using LMKit.Document.Pdf;
using LMKit.Graphics;
var watermark = new Watermark { Text = "CONFIDENTIAL", Opacity = 0.25 };
PdfWatermarkResult result = PdfWatermarker.Apply(new Attachment("contract.pdf"), watermark);
File.WriteAllBytes("contract-marked.pdf", result.Data);
Remarks
Vector, above the content. The mark is drawn from the glyph outlines of its text and its logo image, once per document, as a form xobject every copy on every page refers to: a tiled mark on a hundred pages adds a few kilobytes, stays sharp at any zoom and prints at full resolution. The page's own text, images and structure are not touched: its text stays selectable and searchable.
Identifiable. Every copy is marked content tagged as a pagination artifact of subtype Watermark (ISO 32000-1, 14.8.2.2): assistive technology and text extraction skip it, the mark adds no text to the document, and Remove(Attachment, PdfWatermarkOptions, CancellationToken) takes it off again. Marking a document twice replaces the mark by default (ReplaceExisting).
Refusals. A signed document is refused unless AllowSignatureInvalidation consents to the rewrite that invalidates its signatures. A document declaring PDF/A-1 is refused with NotSupportedException: that part forbids the transparency a watermark needs (PDF/A-2 and PDF/A-3 allow it). Text holding characters no available font can draw is refused with WatermarkCharactersException naming them.
To mark a PDF held as a stream or byte array, wrap it in an Attachment first.
Methods
- Apply(Attachment, Watermark, PdfWatermarkOptions, CancellationToken)
Lays
watermarkover the pages of the PDF insource.
- ApplyAsync(Attachment, Watermark, PdfWatermarkOptions, CancellationToken)
Lays
watermarkover the pages of the PDF insource.
- ApplyToFile(Attachment, Watermark, string, PdfWatermarkOptions, CancellationToken)
Lays
watermarkover the pages of the PDF insourceand writes the result tooutputPath.
- ApplyToFileAsync(Attachment, Watermark, string, PdfWatermarkOptions, CancellationToken)
Lays
watermarkover the pages of the PDF insourceand writes the result tooutputPath.
- Remove(Attachment, PdfWatermarkOptions, CancellationToken)
Removes the watermarks laid by Apply(Attachment, Watermark, PdfWatermarkOptions, CancellationToken) (and any other content marked as a pagination artifact of subtype Watermark) from the pages of the PDF in
source. ReplaceExisting is ignored.
- RemoveAsync(Attachment, PdfWatermarkOptions, CancellationToken)
Removes the watermarks laid by Apply(Attachment, Watermark, PdfWatermarkOptions, CancellationToken) (and any other content marked as a pagination artifact of subtype Watermark) from the pages of the PDF in
source. ReplaceExisting is ignored.