如何将多个图像水印添加到Word文档?试试这款小众工具

*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看优惠价格!想要获取更多福利的朋友可以咨询在线客服哦~

示例代码如下:

import com.spire.doc.Document;import com.spire.doc.FileFormat;import com.spire.doc.HeaderFooter;import com.spire.doc.Section;import com.spire.doc.documents.Paragraph;import com.spire.doc.documents.TextWrappingStyle;import com.spire.doc.fields.DocPicture;public class WordImageWatermark {    public static void main(String[] args) throws Exception {        //Load the sample file        Document doc=new Document();        doc.loadFromFile("Sample.docx");        //Load the image        DocPicture picture = new DocPicture(doc);        picture.loadImage("Logo.png");        //Set the text wrapping style        picture.setTextWrappingStyle(TextWrappingStyle.Behind);        for (int n = 0; n < doc.getSections().getCount(); n++) {            Section section = doc.getSections().get(n);            //Get the head of section            HeaderFooter header = section.getHeadersFooters().getHeader();            Paragraph paragrapg1;            if(header.getParagraphs().getCount()>0){                paragrapg1=header.getParagraphs().get(0);            }else {                //Add the header to the paragraph                paragrapg1 = header.addParagraph();            }            for (int p = 0; p < 3; p++) {                for (int q = 0; q < 2; q++) {                    //copy the image and add it to many places                    picture = (DocPicture)picture.deepClone();                    picture.setVerticalPosition(100 + 200 * p);                    picture.setHorizontalPosition(50 + 210 * q);                    paragrapg1.getChildObjects().add(picture);                }            }        }        //Save the document to file        doc.saveToFile("Result.docx", FileFormat.Docx_2013);    }}

输出:

Word格式处理控件Spire.Doc功能演示:将 Word 转换为受密码保护的 PDF 文档



让人兴奋的是整合所有格式API处理套包Spire.office for Java正在 火热销售中!联系客服立马1分钟了解全部咨询!
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月1日
下一篇 2021年1月1日

相关推荐

发表回复

登录后才能评论