複製鏈接
請複製以下鏈接發送給好友

Itext

鎖定
在企業的信息系統中,報表處理一直佔比較重要的作用,iText是一種生成PDF報表的Java組件。通過在服務器端使用Jsp或JavaBean生成PDF報表,客户端採用超鏈接顯示或下載得到生成的報表,這樣就很好的解決了B/S系統的報表處理問題。
外文名
Itext
作    用
生成PDF文檔
類    型
免費產品

Itext前言

此產品為免費產品。

ItextiText簡介

iText是著名的開放源碼的站點sourceforge一個項目,是用於生成PDF文檔的一個java類庫。通過iText不僅可以生成PDF或rtf的文檔,而且可以將XML、Html文件轉化為PDF文件。 iText的安裝非常方便,下載iText.jar文件後,只需要在系統的CLASSPATH中加入iText.jar的路徑,在程序中就可以使用iText類庫了。

Itext代碼示例

關於字體
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
// 華文中宋
BaseFont bfComic99 = BaseFont.createFont("c:\\windows\\fonts\\STZHONGS.TTF",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//隸書
BaseFont bfComic11= BaseFont.createFont("c:\\windows\\fonts\\SIMLI.TTF",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//宋體&新宋體 (這種字體的輸出不了.有問題)
// BaseFont bfComic12 = BaseFont.createFont("c:\\windows\\fonts\\SIMSUN.TTC", null,
BaseFont.NOT_EMBEDDED, BaseFont.NOT_EMBEDDED, null, null);
//宋體-方正超大字符集
BaseFont bfComic13 = BaseFont.createFont("c:\\windows\\fonts\\SURSONG.TTF",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//幼圓
BaseFont bfComic14 = BaseFont.createFont("c:\\windows\\fonts\\SIMYOU.TTF",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(bfComic0, 14);
String text1 = "啊發生的發球特工是大哥是法國時的風格是This is the quite popular True Type
font (繁體字測試VS簡體字測試) ==>"+new java.util.Date();
document.add(new Paragraph(text1, font));
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
System.out.println(">>> Export : "+"D:\\ChinesePDF005__.pdf");
}
}
這裏調用的都是系統中的字體,如果系統中沒有,找個下下來,在C:/windows/fonts/ 安裝即可。 [1] 
導出word、pdf報表
/**
* 導出PDF示例
* @author raintion [2]  * @param args
*/
public static void main(String[] args) {
try {
Document document = new Document();
PdfWriter. getInstance(document, new FileOutputStream("F:\\test.pdf" ));
document.open();
document.add(new Paragraph( "pride in me!" ));
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
/**
* 導出Word示例
* @author raintion
* @param args
*/
public static void main(String[] args) {
try {
Document document = new Document(PageSize.A4);
RtfWriter2. getInstance(document, new FileOutputStream("F:\\test.doc" ));
document.open();
Paragraph title = new Paragraph("你好 地球人..." );
document.add(title);
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}

Itext需求分析

一般情況下,iText使用在有以下一個要求的項目中:
  • 內容無法提前利用:取決於用户的輸入或實時的數據庫信息。
  • 由於內容,頁面過多,PDF文檔不能手動生成。
  • 文檔需在無人蔘與,批處理模式下自動創建。
  • 內容被定製或個性化;例如,終端客户的名字需要標記在大量的頁面上。
參考資料