Html开发扫描签名图片 合成到word,根据html生成Word文件,包含图片

importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStream;importjava.io.OutputStream;importjava.io.StringReader;importjava.net.URLEncoder;importjava.util.List;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.springframework.web.util.HtmlUtils;importcom.lowagie.text.Document;importcom.lowagie.text.PageSize;importcom.lowagie.text.Paragraph;importcom.lowagie.text.html.simpleparser.HTMLWorker;importcom.lowagie.text.html.simpleparser.StyleSheet;importcom.lowagie.text.rtf.RtfWriter2;importcom.rimi.common.util.Common;public classMSOfficeGeneratorUtils {public static voidhtmlToWord(HttpServletRequest request,HttpServletResponse response,String s){try{

String docUrl=request.getSession().getServletContext().getRealPath("")+File.separator+"fileUpload"+File.separator;

docUrl+=Common.getUUID()+".doc";

OutputStream out= newFileOutputStream(docUrl);

Document document= newDocument(PageSize.A4);

RtfWriter2.getInstance(document, out);

document.open();

Paragraph context= newParagraph();//String value = HtmlUtils.htmlEscape(s);//System.out.println(s);//Image img = Image.getInstance("D:\图片\2.jpg");//img.setAbsolutePosition(0, 0);//

//document.add(img);

StyleSheet ss = newStyleSheet();

List htmlList= HTMLWorker.parseToList(newStringReader(s), ss);for (int i = 0; i < htmlList.size(); i++) {

com.lowagie.text.Element e=(com.lowagie.text.Element) htmlList

.get(i);

context.add(e);

}

document.add(context);

document.close();

out.close();

InputStream inStream= newFileInputStream(docUrl);

response.reset();

response.setContentType("bin");

response.addHeader("Content-Disposition","attachment; filename=""

+ URLEncoder.encode("试题文档.doc","UTF-8") + """);//循环取出流中的数据

byte[] b = new byte[512];intlen;

response.getOutputStream().flush();while ((len = inStream.read(b)) > 0) {

response.getOutputStream().write(b,0, len);

}

inStream.close();//System.out.println("ok");

} catch(Exception e) {

e.printStackTrace();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值