zoukankan      html  css  js  c++  java
  • Itext中 根据html生成Word文件,包含图片

     1     package cn.com.wzf;  
     2       
     3     import java.io.FileOutputStream;  
     4     import java.io.OutputStream;  
     5     import java.io.StringReader;  
     6     import java.util.List;  
     7       
     8     import com.lowagie.text.Document;  
     9     import com.lowagie.text.PageSize;  
    10     import com.lowagie.text.Paragraph;  
    11     import com.lowagie.text.html.simpleparser.HTMLWorker;  
    12     import com.lowagie.text.html.simpleparser.StyleSheet;  
    13     import com.lowagie.text.rtf.RtfWriter2;  
    14       
    15     public class ItextCreateRTF {  
    16         public static void main(String[] args) throws Exception {  
    17             OutputStream out = new FileOutputStream("c://a.doc");  
    18             Document document = new Document(PageSize.A4);  
    19             RtfWriter2.getInstance(document, out);  
    20             document.open();  
    21             Paragraph context = new Paragraph();  
    22             String s = "上传的图片<img width="800" height="600" alt="" src="http://localhost:8081/zhmobileexp/upload/activity/photos/Image/waterlilies.jpg" />";  
    23             System.out.println(s);  
    24             // Image img = Image.getInstance("D:\图片\2.jpg");  
    25             // img.setAbsolutePosition(0, 0);//  
    26             // document.add(img);  
    27             StyleSheet ss = new StyleSheet();  
    28             List htmlList = HTMLWorker.parseToList(new StringReader(s), ss);  
    29             for (int i = 0; i < htmlList.size(); i++) {  
    30                 com.lowagie.text.Element e = (com.lowagie.text.Element) htmlList  
    31                         .get(i);  
    32                 context.add(e);  
    33             }  
    34             document.add(context);  
    35             document.close();  
    36             System.out.println("ok");  
    37         }  
    38     }  
  • 相关阅读:
    bzoj4537: [Hnoi2016]最小公倍数
    bzoj4331: JSOI2012 越狱老虎桥
    bzoj4558: [JLoi2016]方
    bzoj4209: 西瓜王
    bzoj2653: middle
    bzoj4671: 异或图
    bzoj4771: 七彩树
    shell java应用启动脚本(app.sh)
    Springboot 构建http服务,返回的http行是'HTTP/1.1 200' 无状态码描述 客户端解析错误
    MariaDB(Mysql)-主从搭建
  • 原文地址:https://www.cnblogs.com/SK1995/p/5863912.html
Copyright © 2011-2022 走看看