翻譯|使用教程|編輯:李顯亮|2021-02-03 13:30:32.910|閱讀 269 次
概述:本文將向您展示如何將藝術(shù)字添加到Word標(biāo)頭以獲取Word文檔上的多個(gè)水印。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for Java 是一款專業(yè)的Java Word組件,開發(fā)人員使用它可以輕松地將Word文檔創(chuàng)建、讀取、編輯、轉(zhuǎn)換和打印等功能集成到自己的Java應(yīng)用程序中。
本文將向您展示如何借助Spire.Doc for Java將多個(gè)圖像水印添加到Word文檔中。可點(diǎn)擊此處下載最新版測試。
示例代碼如下:
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); } }
輸出:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn