2013-02-22 84 views
1

我想用嵌入圖像生成一個.doc文件。目前我正面臨一個問題,即我從我的jsp腳本動態生成的文件在離線模式下不顯示圖像。我希望得到他們的嵌入式像原來的​​文檔,這樣他們將可以查看離線使用用jsp生成圖像嵌入式doc文件

請幫助

回答

0

您可以使用apache POI來生成doc文件,並插入圖片,如:

String savePath= "c:\\temp\\"; 
String docFile= savePath+ "test.doc"; 
String imgFile= savePath+ "img.jpg"; 

HWPFDocument poiDoc = new HWPFDocument(new FileInputStream(docFile)); 
    List picList=poiDoc.getPicturesTable().getAllPictures(); 
    Picture picture=(Picture)picList.get(0); 
    try { 
      picture.writeImageContent(new FileOutputStream(imgFile)); 
     } catch (FileNotFoundException e) { 
       e.printStackTrace();  
}