In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "Java how to add watermarks to Word documents", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Java how to add watermarks to Word documents" it!
Generally, you can set a text watermark or load a picture as a watermark. Generally, you can set a text watermark or load a picture as a watermark. The following will share ways to add watermarking effects to Word documents through Java programming, namely
Text watermarking
Image watermark
Using tools: Free Spire.Doc for Java (free version)
Jar Import:
Method 1: download the jar (https://www.e-iceblue.cn/Introduce/Free-Spire-Doc-JAVA.html) package through the official website. After downloading, extract the file and import the Spire.Doc.jar file under the lib folder into the java program. Refer to the following import effect:
Method 2: import through maven. Refer to Import method (https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html).
Java code example (for reference)
1. Add a text watermark
Import com.spire.doc.*;import com.spire.doc.documents.WatermarkLayout;import java.awt.*; public class Main {public static void main (String [] args) {/ / load test document Document document = new Document (); document.loadFromFile ("sample.docx"); / / insert text watermark InsertTextWatermark (document.getSections () .get (0)) / / Save document document.saveToFile ("textwatermark.docx", FileFormat.Docx);} / / Custom method inserts text watermark and formats watermark effect private static void InsertTextWatermark (Section section) {TextWatermark txtWatermark = new TextWatermark (); txtWatermark.setText ("Internal use"); txtWatermark.setFontSize (40); txtWatermark.setColor (Color.red); txtWatermark.setLayout (WatermarkLayout.Diagonal) Section.getDocument () .setWatermark (txtWatermark);}
Text watermarking effect:
two。 Add a picture watermark
Import com.spire.doc.*; public class Main {public static void main (String [] args) {/ / load test document Document document = new Document (); document.loadFromFile ("sample.docx"); / / load picture as watermark PictureWatermark picture = new PictureWatermark (); picture.setPicture ("wx.png"); picture.setScaling (5); picture.isWashout (false) Document.setWatermark (picture); / / Save document document.saveToFile ("imagewatermark.docx", FileFormat.Docx);}}
Image watermarking effect:
Thank you for your reading, the above is the content of "Java how to add watermarks to Word documents", after the study of this article, I believe you have a deeper understanding of how Java adds watermarks to Word documents, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.