Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 19, 2021 10:47
Show Gist options
  • Save aspose-com-gists/9c2cf3f92d75b861f1d1c51de1d791c5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/9c2cf3f92d75b861f1d1c51de1d791c5 to your computer and use it in GitHub Desktop.
Add Watermark to Word Documents in Java
// Load the Word document
Document doc = new Document("Word.docx");
// Set watermark options
ImageWatermarkOptions watermarkOptions = new ImageWatermarkOptions();
watermarkOptions.isWashout(false);
// Load watermark image
BufferedImage image = ImageIO.read(new File("logo.png"));
// Insert watermark
doc.getWatermark().setImage(image, watermarkOptions);
// Save the updated document
doc.save("image-watermark.docx");
// Load the Word document
Document doc = new Document("Word.docx");
// Set watermark options
TextWatermarkOptions watermarkOptions = new TextWatermarkOptions();
watermarkOptions.setFontSize(36);
watermarkOptions.setFontFamily("Arial");
watermarkOptions.setColor(Color.RED);
watermarkOptions.setLayout(WatermarkLayout.DIAGONAL);
watermarkOptions.isSemitrasparent(true);
// Insert watermark
doc.getWatermark().setText("CONFIDENTIAL", watermarkOptions);
// Save the updated document
doc.save("text-watermark.docx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment