Adding a Watermark to Converted Documents
Leave feedback
GroupDocs.Conversion provides a flexible way to apply watermarks to documents during the conversion process. This feature can be useful for branding, security, or informational purposes. You can customize various aspects of the watermark, such as its text, size, color, position, and transparency.
Tip
Looking for advanced watermarking capabilities? While GroupDocs.Conversion offers basic watermarking, you can explore GroupDocs.Watermark for a comprehensive solution with enhanced features.
WatermarkOptions
You can control how the watermark appears in the converted document using the WatermarkOptions class. Here are the key properties you can set:
Determines whether the watermark is stamped as a background. If set to true, the watermark appears behind the document content. By default, it is set to false, meaning the watermark will appear on top of the content.
Enables or disables automatic alignment of the watermark on the document. When set to true, the watermark will be automatically positioned to best fit the content layout, ensuring optimal visibility and aesthetics. When set to false, the watermark will retain its manually defined position.
Steps to Add a Watermark
Initialize the Converter: Create an instance of the Converter class, providing the path to the source document.
Set Conversion Options: Instantiate the appropriate ConvertOptions class (e.g., PdfConvertOptions, WordProcessingConvertOptions, SpreadsheetConvertOptions, etc.).
Configure Watermark Options: Create an instance of the WatermarkOptions class and configure the properties to specify the watermark’s appearance.
Apply the Watermark: Use the setWatermark method of the ConvertOptions instance to apply the watermark settings.
Convert the Document: Call the convert method on the Converter instance, passing the output file name and the configured ConvertOptions instance.
Example: Add a Text Watermark to Converted Document
The following Java code snippet demonstrates how to apply a text watermark to a document during conversion to PDF:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;importcom.groupdocs.conversion.options.convert.WatermarkTextOptions;publicclassAddWatermarkToConvertedDocument{publicstaticvoidconvert(){// Initialize the converter with the source document
try(Converterconverter=newConverter("annual-review.docx")){// Set conversion options for PDF
PdfConvertOptionsoptions=newPdfConvertOptions();// Configure watermark options
WatermarkTextOptionswatermark=newWatermarkTextOptions("Sample Watermark");watermark.setColor(Color.RED);// Set watermark color to red
watermark.setWidth(100);// Set watermark width
watermark.setHeight(100);// Set watermark height
watermark.setBackground(true);// Set watermark as background
// Apply the watermark to the conversion options
options.setWatermark(watermark);// Convert the document and apply the watermark
converter.convert("addTextWatermark.pdf",options);}}publicstaticvoidmain(String[]args){convert();}}
annual-review.docx is sample file used in this example. Click here to download it.
addTextWatermark.pdf is converted PDF document. Click here to download it.
By following these steps and adjusting the settings, you can easily add customized watermarks to your converted documents using GroupDocs.Conversion.
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.