The watermark can be removed from the PDF documents using third-party tools. However, if you want to remove a watermark that is almost impossible to remove, you can rasterize pdf documents. 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"using(Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions)){// Initialize image or text watermarkTextWatermarkwatermark=newTextWatermark("Do not copy",newFont("Arial",8));watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermark.RotateAngle=45;watermark.SizingType=SizingType.ScaleToParentDimensions;watermark.ScaleFactor=1;watermark.Opacity=0.5;// Add watermark of any type firstwatermarker.Add(watermark);PdfContentpdfContent=watermarker.GetContent<PdfContent>();// Rasterize all pagespdfContent.Rasterize(100,100,PdfImageConversionFormat.Png);// Content of all pages is replaced with raster imageswatermarker.Save("document.pdf");}
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"using(Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions)){// Initialize image or text watermarkTextWatermarkwatermark=newTextWatermark("Do not copy",newFont("Arial",8));watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermark.RotateAngle=45;watermark.SizingType=SizingType.ScaleToParentDimensions;watermark.ScaleFactor=1;watermark.Opacity=0.5;// Add watermark of any type firstPdfArtifactWatermarkOptionsoptions=newPdfArtifactWatermarkOptions();options.PageIndex=0;watermarker.Add(watermark,options);// Rasterize the first pagePdfContentpdfContent=watermarker.GetContent<PdfContent>();pdfContent.Pages[0].Rasterize(100,100,PdfImageConversionFormat.Png);// Content of the first page is replaced with raster imagewatermarker.Save("document.pdf");}
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.