Watermarks in PDFs can be removed by third-party tools. If you need watermarks that are very hard to remove, rasterize the document: convert pages to images so content becomes non-editable.
Rasterize PDF document
This sample converts all PDF pages to images (after adding a watermark) to lock down content and make subsequent removal extremely difficult.
importgroupdocs.watermarkasgwimportgroupdocs.watermark.contents.pdfasgwc_pdfimportgroupdocs.watermark.watermarksasgwwimportgroupdocs.watermark.commonasgwcload_options=gw.PdfLoadOptions()withgw.Watermarker("document.pdf",load_options)aswatermarker:watermark=gww.TextWatermark("Do not copy",gww.Font("Arial",8.0))watermark.horizontal_alignment=gwc.HorizontalAlignment.CENTERwatermark.vertical_alignment=gwc.VerticalAlignment.CENTERwatermark.rotate_angle=45watermark.sizing_type=gww.SizingType.SCALE_TO_PARENT_DIMENSIONSwatermark.scale_factor=1.0watermark.opacity=0.5watermarker.add(watermark)pdf_content=watermarker.get_content(gwc_pdf.PdfContent)pdf_content.rasterize(100,100,gwc_pdf.PdfImageConversionFormat.PNG)watermarker.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
This sample rasterizes only a specified page of the PDF (with an applied watermark), leaving the rest of the document editable.
importgroupdocs.watermarkasgwimportgroupdocs.watermark.contents.pdfasgwc_pdfimportgroupdocs.watermark.watermarksasgwwimportgroupdocs.watermark.commonasgwcimportgroupdocs.watermark.options.pdfasgwo_pdfload_options=gw.PdfLoadOptions()withgw.Watermarker("document.pdf",load_options)aswatermarker:watermark=gww.TextWatermark("Do not copy",gww.Font("Arial",8.0))watermark.horizontal_alignment=gwc.HorizontalAlignment.CENTERwatermark.vertical_alignment=gwc.VerticalAlignment.CENTERwatermark.rotate_angle=45watermark.sizing_type=gww.SizingType.SCALE_TO_PARENT_DIMENSIONSwatermark.scale_factor=1.0watermark.opacity=0.5options=gwo_pdf.PdfArtifactWatermarkOptions()options.page_index=0watermarker.add(watermark,options)pdf_content=watermarker.get_content(gwc_pdf.PdfContent)pdf_content.pages[0].rasterize(100,100,gwc_pdf.PdfImageConversionFormat.PNG)watermarker.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.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.