Android
ComPDFKit PDF SDK
Guides

Watermark

 

Adding a non-removable watermark to documents can discourage viewers from sharing your content or taking screenshots.

- To get the the CPDFWatermark at the specified index in this list, use function CPDFDocument.getWatermark(int index).

- To add a watermark, use function CPDFDocument.createWatermark(CPDFWatermark.Type type).

- To remove the watermark, use function CPDFWatermark.clear().

- To update the watermark, use function CPDFWatermark.update().

 

How to generate a PDF with a watermark on all its pages using the CPDFDocument API:

CPDFTextWatermark textWatermark = (CPDFTextWatermark) document.createWatermark(CPDFWatermark.Type.WATERMARK_TYPE_TEXT);
try {
 if (textWatermark != null && textWatermark.isValid()) {
   textWatermark.setText("Hello World");
   textWatermark.setFontName("Helvetica");
   textWatermark.setTextRGBColor(ColorUtils.parseColor(color));
   textWatermark.setOpacity(0.5f);
   textWatermark.setFontSize(30);
   textWatermark.setFront(true);
   textWatermark.setVertalign(CPDFWatermark.Vertalign.WATERMARK_VERTALIGN_CENTER);
   textWatermark.setHorizalign(CPDFWatermark.Horizalign.WATERMARK_HORIZALIGN_CENTER);
   textWatermark.setVertOffset(0);
   textWatermark.setHorizOffset(0);
   textWatermark.setScale(1.3f);
   textWatermark.setPages("3,4,5");
   textWatermark.setFullScreen(true);
   textWatermark.setHorizontalSpacing(100);
   textWatermark.setVerticalSpacing(100);
   textWatermark.update();
}
} finally {
 if (textWatermark != null && textWatermark.isValid()) {
   textWatermark.release();
}
}