PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
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
API Overview
Watermark APIs are available on CPDFDocument:
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();| API | Description |
|---|---|
createWatermark | Adds a text or image watermark to the document. |
getWatermarkCount | Gets the number of watermarks in the document. |
getWatermark | Gets one watermark by index. |
getWatermarks | Gets all watermarks in the document. |
updateWatermark | Updates an existing watermark by index. |
removeWatermark | Removes one watermark by index. |
removeAllWatermarks | Removes all watermarks from the document. |
Watermark Model
Use CPDFWatermark.text to create a text watermark and CPDFWatermark.image to create an image watermark.
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,
});| Option | Description |
|---|---|
pages | Zero-based page indexes where the watermark is applied. |
scale | Watermark scale factor. |
rotation | Watermark rotation angle in degrees. |
opacity | Watermark opacity, from 0.0 to 1.0. |
verticalAlignment | Vertical position: top, center, or bottom. |
horizontalAlignment | Horizontal position: left, center, or right. |
verticalOffset | Vertical offset from the selected alignment position. |
horizontalOffset | Horizontal offset from the selected alignment position. |
isFront | Whether the watermark is drawn above page content. |
isTilePage | Whether the watermark is repeated across the page. |
horizontalSpacing | Horizontal spacing for tiled watermarks. |
verticalSpacing | Vertical spacing for tiled watermarks. |
Guides
Create text watermarks with custom content and appearance.
Create image watermarks from custom images.
Remove watermarks from the PDF document.
Get watermark information and export image watermark content.
Update selected properties of an existing watermark.