The watermark can be removed from the PDF documents using third-party tools. However, if you want to get a watermark that is almost impossible to remove, you can consider PDF document rasterization. GroupDocs.Watermark provides the feature to convert all the pages of a PDF document to raster images with only one line of code.
Rasterize PDF document
Following code snippet is used to rasterize the PDF document to protect added watermarks.
PdfLoadOptionsloadOptions=newPdfLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions);// Initialize image or text watermark
TextWatermarkwatermark=newTextWatermark("Do not copy",newFont("Arial",8));watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);watermark.setRotateAngle(45);watermark.setSizingType(SizingType.ScaleToParentDimensions);watermark.setScaleFactor(1);watermark.setOpacity(0.5);// Add watermark of any type first
watermarker.add(watermark);PdfContentpdfContent=watermarker.getContent(PdfContent.class);// Rasterize all pages
pdfContent.rasterize(100,100,PdfImageConversionFormat.Png);// Content of all pages is replaced with raster images
watermarker.save("document.pdf");watermarker.close();
Warning
You can’t restore document content after saving the document. Rasterization significantly increases the size of the resultant PDF file.
Rasterize particular page of the PDF document
The API also allows you to rasterize any particular page of the PDF document. Following code snippet is used to rasterize a page of the PDF document.
PdfLoadOptionsloadOptions=newPdfLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions);// Initialize image or text watermark
TextWatermarkwatermark=newTextWatermark("Do not copy",newFont("Arial",8));watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);watermark.setRotateAngle(45);watermark.setSizingType(SizingType.ScaleToParentDimensions);watermark.setScaleFactor(1);watermark.setOpacity(0.5);// Add watermark of any type first
PdfArtifactWatermarkOptionsoptions=newPdfArtifactWatermarkOptions();options.setPageIndex(0);watermarker.add(watermark,options);// Rasterize the first page
PdfContentpdfContent=watermarker.getContent(PdfContent.class);pdfContent.getPages().get_Item(0).rasterize(100,100,PdfImageConversionFormat.Png);// Content of the first page is replaced with raster image
watermarker.save("document.pdf");watermarker.close();
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.