Add watermarks to a particular page or to all images/attachments on a page.
Adding watermark to a particular page
importgroupdocs.watermarkasgwimportgroupdocs.watermark.watermarksasgwwimportgroupdocs.watermark.options.pdfasgwo_pdfload_options=gw.PdfLoadOptions()withgw.Watermarker("document.pdf",load_options)aswatermarker:text_watermark=gww.TextWatermark("This is a test watermark",gww.Font("Arial",8.0))text_opts=gwo_pdf.PdfArtifactWatermarkOptions()text_opts.page_index=0watermarker.add(text_watermark,text_opts)withgww.ImageWatermark("protect.jpg")asimg_wm:img_opts=gwo_pdf.PdfArtifactWatermarkOptions()img_opts.page_index=1watermarker.add(img_wm,img_opts)watermarker.save("document.pdf")
Adding watermark to all images of a particular page
importgroupdocs.watermarkasgwimportgroupdocs.watermark.contents.pdfasgwc_pdfimportgroupdocs.watermark.watermarksasgwwfromgroupdocs.watermark.commonimportFileTypewatermark=gww.TextWatermark("This is WaterMark on Attachment",gww.Font("Arial",19.0))load_options=gw.PdfLoadOptions()withgw.Watermarker("document.pdf",load_options)aswatermarker:pdf_content=watermarker.get_content(gwc_pdf.PdfContent)forattachmentinpdf_content.attachments:info=attachment.get_document_info()ifinfo.file_type!=FileType.UNKNOWNandnotinfo.is_encrypted:withattachment.create_watermarker()asattached:attached.add(watermark)attached.save()watermarker.save("document.pdf")