Add image into a word .docx document header using Apache POI XWPF

亡梦爱人 提交于 2019-12-13 03:51:13

问题


Can anyone please help me to add image into word document (.docx) header using Apache POI's XWPF component?.

I tried very hard, but unable to find solution.


回答1:


XWPFDocument doc = new XWPFDocument();

FileInputStream fis = new FileInputStream("/images/image.png"); 
XWPFParagraph par1 = doc.createParagraph();
XWPFRun runAppName = par1.createRun();  
runAppName.addPicture(fis, Document.PICTURE_TYPE_PNG, "image.png", 257, 185);

doc.write(new FileOutputStream(new File("/folder/document.docx")));


来源:https://stackoverflow.com/questions/21235868/add-image-into-a-word-docx-document-header-using-apache-poi-xwpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!