Related Article(s):
Last active
August 31, 2023 12:45
-
-
Save GroupDocsGists/bf2b396740c26684337b4512f081247d to your computer and use it in GitHub Desktop.
Add Watermarks to Word Documents using Java | Text and Image Watermarks
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
// Apply Image Watermark to specific page(s) of Word file using Java | |
Watermarker watermarker = new Watermarker("path/document.docx"); | |
ImageWatermark watermark = new ImageWatermark("path/watermark-logo.png"); | |
watermark.setOpacity(0.7); | |
watermark.setHorizontalAlignment(HorizontalAlignment.Center); | |
watermark.setVerticalAlignment(VerticalAlignment.Center); | |
// Add watermark to the last page | |
WordProcessingContent content = watermarker.getContent(WordProcessingContent.class); | |
WordProcessingWatermarkPagesOptions options = new WordProcessingWatermarkPagesOptions(); | |
options.setPageNumbers(new int[] {content.getPageCount()}); | |
watermarker.add(watermark); | |
watermarker.save("path/image-watermark.docx"); | |
watermark.close(); | |
watermarker.close(); |
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
// Apply Text Watermark to all pages of Word file using Java | |
Watermarker watermarker = new Watermarker("path/document.docx"); | |
TextWatermark textWatermark = new TextWatermark("Watermark", new Font("Arial", 80)); | |
textWatermark.setRotateAngle(-45); | |
textWatermark.setOpacity(0.3); | |
textWatermark.setForegroundColor(Color.getDarkBlue()); | |
textWatermark.setHorizontalAlignment(HorizontalAlignment.Center); | |
textWatermark.setVerticalAlignment(VerticalAlignment.Center); | |
watermarker.add(textWatermark); | |
// Save the watermarked Word file | |
watermarker.save("path/watermarked.docx"); | |
watermarker.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment