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 htmlcontent = "<img src='http://localhost:8081/project/image/a.jpg'/>";
stylesheet ss = new stylesheet();
list htmllist = htmlworker.parsetolist(new stringreader(htmlcontent),
ss);
for (int i = ; 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");
}
}
htmlcontent就是需要轉化成word文檔的html内容。可以是圖檔,也可以是其他任何html内容。它會将html标簽解析為格式。原帖位址裡有更詳細的對圖檔的操作。
原帖位址:http://af8991.iteye.com/blog/853107