资源简介
java实现生成PDF文档代码及jar
代码片段和文件信息
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Date;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.baseFont;
import com.lowagie.text.pdf.PdfCell;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPRow;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.sun.java_cup.internal.internal_error;
public class PDFReport{
Document document = new Document();// 建立一个Document对象
private static Font headfont ;// 设置字体大小
private static Font keyfont;// 设置字体大小
private static Font textfont;// 设置字体大小
static{
baseFont bfChinese;
try {
//bfChinese = baseFont.createFont(“STSong-Light““UniGB-UCS2-H“baseFont.NOT_embedDED);
bfChinese = baseFont.createFont(“STSong-Light““UniGB-UCS2-H“baseFont.NOT_embedDED);
headfont = new Font(bfChinese 10 Font.BOLD);// 设置字体大小
keyfont = new Font(bfChinese 8 Font.BOLD);// 设置字体大小
textfont = new Font(bfChinese 8 Font.NORMAL);// 设置字体大小
} catch (Exception e) {
e.printStackTrace();
}
}
public PDFReport(File file) {
document.setPageSize(PageSize.A4);// 设置页面大小
try {
PdfWriter.getInstance(documentnew FileOutputStream(file));
document.open();
} catch (Exception e) {
e.printStackTrace();
}
}
int maxWidth = 520;
public PdfPCell createCell(String valuecom.lowagie.text.Font fontint align){
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(align);
cell.setPhrase(new Phrase(valuefont));
return cell;
}
public PdfPCell createCell(String valuecom.lowagie.text.Font font){
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPhrase(new Phrase(valuefont));
return cell;
}
public PdfPCell createCell(String valuecom.lowagie.text.Font fontint alignint colspan){
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(align);
cell.setColspan(colspan);
cell.setPhrase(new Phrase(valuefont));
return cell;
}
public PdfPCell createCell(String valuecom.lowagie.text.Font fontint alignint colspanboolean boderFlag){
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setHorizontalAlignment(align);
cell.setColspan(colspan);
cell.setPhrase(new Phrase(valuefont));
cell.setPadding(3.0f);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5162 2011-08-29 14:58 PDFReport.java
文件 1138572 2011-08-24 09:38 iText-2.1.6.jar
文件 331811 2011-08-24 09:38 iTextAsian.jar
----------- --------- ---------- ----- ----
1475545 3
评论
共有 条评论