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");  
        }  
    }
    

     

  • 相关阅读:
    数组
    分支.顺序结构
    博客作业-查找
    DS博客作业-图
    DS 数据结构-树
    数据结构-栈,队列
    博客作业05-指针
    C语言博客作业04-数组
    C语言博客作业03——函数
    c语言博客作业02-循环结构
  • 原文地址:https://www.cnblogs.com/SK1995/p/5887824.html
Copyright © 2011-2022 走看看