use itext to create a html
2008-01-05 20:01:54 来源:WEB开发网import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import com.lowagie.text.*;
import com.lowagie.text.Html.HtmlWriter;
/*
* Created on 2004-11-10
*
*/
/**
* @author Liao Chuan(liao_chuan@shhicom.com.cn)
*
*/
public class HTMLCreate {
public static void main(String[] args) throws MalformedURLException, IOException {
HTMLCreate htmlCreate = new HTMLCreate();
try {
htmlCreate.createHTML();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.PRintStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void createHTML() throws DocumentException, BadElementException, MalformedURLException, IOException
{
Document document = new Document(PageSize.A4);
//document.addTitle("Title");
//document.addHeader("header","Header");
HtmlWriter.getInstance(document, new FileOutputStream("C:/World.html"));
document.open();
//add a Word
document.add(new Paragraph("Hello World!您好!hehe!"));
//add a table
Table table = new Table(3);
table.setBorderWidth(1);
table.setBorderColor(new Color(0, 0, 255));
table.setPadding(5);
table.setSpacing(5);
Cell cell = new Cell("header");
cell.setHeader(true);
cell.setColspan(3);
table.addCell(cell);
table.endHeaders();
cell = new Cell("example cell with colspan 1 and rowspan 2");
cell.setRowspan(2);
cell.setBorderColor(new Color(255, 0, 0));
table.addCell(cell);
table.addCell("1.1");
table.addCell("2.1");
table.addCell("1.2");
table.addCell("2.2");
table.addCell("cell test1");
cell = new Cell("big cell");
cell.setRowspan(2);
cell.setColspan(2);
table.addCell(cell);
table.addCell("cell test2");
document.add(table);
Image png = Image.getInstance("workswithMySQL.png");
- ››user-agent查询方法
- ››TOscilloscope 仿Windows任务管理器CPU使用记录组...
- ››tomcat不支持TCP/IP6协议
- ››tomcat 下的 url 大小写问题
- ››tomcat6.0.28 内存溢出PermGen Space
- ››Tomcat 系统架构与设计模式,第 2 部分: 设计模式...
- ››Tomcat 系统架构与设计模式,第 1 部分: 工作原理...
- ››TOMCAT和IIS整合
- ››userinit.exe出现异常之解决方案
- ››Tomcat性能调优方案
- ››Tomcat6 下 MySQL 5.1 数据源配制
- ››Tomcat启动分析server.xml
更多精彩
赞助商链接