Skip to content
ComPDF
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Guides

Overview

A watermark is a mark placed on a PDF document, usually in the form of semi-transparent text or image elements. By adding a watermark, you can highlight ownership or other relevant information without interfering with the readability of the document.

Advantages of ComPDF Watermarks

  • Copyright Marking: Display document source and copyright information through watermarks to prevent screenshots or misuse.
  • Branding: Customize watermark appearance to showcase your brand's logo or other preset content.
  • Quick UI Integration: Easily integrate and customize watermarks using scalable UI components.

API Overview

Watermark APIs are available on CPDFDocument:

dart
Future<bool> createWatermark(CPDFWatermark watermark);

Future<int> getWatermarkCount();

Future<CPDFWatermark?> getWatermark(
  int index, {
  bool exportImage = false,
});

Future<List<CPDFWatermark>> getWatermarks({
  bool exportImages = false,
});

Future<bool> updateWatermark(int index, CPDFWatermark watermark);

Future<bool> removeWatermark(int index);

Future<void> removeAllWatermarks();
APIDescription
createWatermarkAdds a text or image watermark to the document.
getWatermarkCountGets the number of watermarks in the document.
getWatermarkGets one watermark by index.
getWatermarksGets all watermarks in the document.
updateWatermarkUpdates an existing watermark by index.
removeWatermarkRemoves one watermark by index.
removeAllWatermarksRemoves all watermarks from the document.

Watermark Model

Use CPDFWatermark.text to create a text watermark and CPDFWatermark.image to create an image watermark.

dart
CPDFWatermark.text({
  required String textContent,
  required List<int> pages,
  Color textColor = Colors.black,
  int fontSize = 24,
  double scale = 1.0,
  double rotation = 45,
  double opacity = 1,
  CPDFWatermarkVerticalAlignment verticalAlignment =
      CPDFWatermarkVerticalAlignment.center,
  CPDFWatermarkHorizontalAlignment horizontalAlignment =
      CPDFWatermarkHorizontalAlignment.center,
  double verticalOffset = 0,
  double horizontalOffset = 0,
  bool isFront = true,
  bool isTilePage = false,
  double horizontalSpacing = 0,
  double verticalSpacing = 0,
});

CPDFWatermark.image({
  required String imagePath,
  required List<int> pages,
  double scale = 1.0,
  double rotation = 45,
  double opacity = 1,
  CPDFWatermarkVerticalAlignment verticalAlignment =
      CPDFWatermarkVerticalAlignment.center,
  CPDFWatermarkHorizontalAlignment horizontalAlignment =
      CPDFWatermarkHorizontalAlignment.center,
  double verticalOffset = 0,
  double horizontalOffset = 0,
  bool isFront = true,
  bool isTilePage = false,
  double horizontalSpacing = 0,
  double verticalSpacing = 0,
});
OptionDescription
pagesZero-based page indexes where the watermark is applied.
scaleWatermark scale factor.
rotationWatermark rotation angle in degrees.
opacityWatermark opacity, from 0.0 to 1.0.
verticalAlignmentVertical position: top, center, or bottom.
horizontalAlignmentHorizontal position: left, center, or right.
verticalOffsetVertical offset from the selected alignment position.
horizontalOffsetHorizontal offset from the selected alignment position.
isFrontWhether the watermark is drawn above page content.
isTilePageWhether the watermark is repeated across the page.
horizontalSpacingHorizontal spacing for tiled watermarks.
verticalSpacingVertical spacing for tiled watermarks.

Guides