1 packagecom.itext.test;2
3 importjava.io.FileOutputStream;4
5 importcom.itextpdf.text.BaseColor;6 importcom.itextpdf.text.Document;7 importcom.itextpdf.text.Element;8 importcom.itextpdf.text.Image;9 importcom.itextpdf.text.PageSize;10 importcom.itextpdf.text.Paragraph;11 importcom.itextpdf.text.pdf.BaseFont;12 importcom.itextpdf.text.pdf.PdfPCell;13 importcom.itextpdf.text.pdf.PdfPTable;14 importcom.itextpdf.text.pdf.PdfWriter;15
16
17 public classBaoXiaoDan {18 public static voidmain(String[] args) {19
20 try
21 {22 Document document = newDocument(PageSize.A4.rotate());23 PdfWriter.getInstance(document, new FileOutputStream("D:\\Helloworld.PDF"));24
25 //设置字体
26 BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);27 com.itextpdf.text.Font FontChinese24 = new com.itextpdf.text.Font(bfChinese, 24, com.itextpdf.text.Font.BOLD);28 com.itextpdf.text.Font FontChinese18 = new com.itextpdf.text.Font(bfChinese, 18, com.itextpdf.text.Font.BOLD);29 com.itextpdf.text.Font FontChinese16 = new com.itextpdf.text.Font(bfChinese, 16, com.itextpdf.text.Font.BOLD);30 com.itextpdf.text.Font FontChinese12 = new com.itextpdf.text.Font(bfChinese, 12, com.itextpdf.text.Font.NORMAL);31 com.itextpdf.text.Font FontChinese11Bold = new com.itextpdf.text.Font(bfChinese, 11, com.itextpdf.text.Font.BOLD);32 com.itextpdf.text.Font FontChinese11 = new com.itextpdf.text.Font(bfChinese, 11, com.itextpdf.text.Font.ITALIC);33 com.itextpdf.text.Font FontChinese11Normal = new com.itextpdf.text.Font(bfChinese, 11, com.itextpdf.text.Font.NORMAL);34
35 document.open();36 //table1
37 PdfPTable table1 = new PdfPTable(3);38 PdfPCell cell11 = new PdfPCell(new Paragraph("费用报销",FontChinese24));39 cell11.setVerticalAlignment(Element.ALIGN_MIDDLE);40 cell11.setHorizontalAlignment(Element.ALIGN_CENTER);41 cell11.setBorder(0);42 String imagePath = "D:/alibaba.jpg";43 Image image1 =Image.getInstance(imagePath);44
45 Image image2 =Image.getInstance(imagePath);46 //设置每列宽度比例
47 i