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

    package cn.com.wzf;  
      
    import java.io.FileOutputStream;  
    import java.io.OutputStream;  
    import java.io.StringReader;  
    import java.util.List;  
      
    import com.lowagie.text.Document;  
    import com.lowagie.text.PageSize;  
    import com.lowagie.text.Paragraph;  
    import com.lowagie.text.html.simpleparser.HTMLWorker;  
    import com.lowagie.text.html.simpleparser.StyleSheet;  
    import com.lowagie.text.rtf.RtfWriter2;  
      
    public class ItextCreateRTF {  
        public static void main(String[] args) throws Exception {  
            OutputStream out = new FileOutputStream("c://a.doc");  
            Document document = new Document(PageSize.A4);  
            RtfWriter2.getInstance(document, out);  
            document.open();  
            Paragraph context = new Paragraph();  
            String s = "上传的图片<img width="800" height="600" alt="" src="http://localhost:8081/zhmobileexp/upload/activity/photos/Image/waterlilies.jpg" />";  
            System.out.println(s);  
            // Image img = Image.getInstance("D:\图片\2.jpg");  
            // img.setAbsolutePosition(0, 0);//  
            // document.add(img);  
            StyleSheet ss = new StyleSheet();  
            List htmlList = HTMLWorker.parseToList(new StringReader(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();  
            System.out.println("ok");  
        }  
    }
    

     

  • 相关阅读:
    Redis_常用5大数据类型简介
    redis_安装
    Redis_NoSql分布式数据库CAP原理
    redis_NoSql数据库四大分类
    redis_NoSql入门概述数据模型简介
    redis_NoSql入门概述
    NGINX下配置CACHE-CONTROL
    (转)centos6.5安装VNC
    django出现__init__() got an unexpected keyword argument 'mimetype‘ 问题解决
    凌乱的2015
  • 原文地址:https://www.cnblogs.com/SK1995/p/5887824.html
Copyright © 2011-2022 走看看