Read the complete article on adding watermark to Word documents in Java: https://blog.aspose.com/2021/07/19/add-watermark-to-word-documents-using-java/
Last active
July 19, 2021 10:47
-
-
Save aspose-com-gists/9c2cf3f92d75b861f1d1c51de1d791c5 to your computer and use it in GitHub Desktop.
Add Watermark to Word Documents in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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