利用Itext生成PDF實例

gbd8 9年前發布 | 2K 次閱讀 Java

    import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.Document;  
import com.itextpdf.text.DocumentException;  
import com.itextpdf.text.Element;  
import com.itextpdf.text.Font;  
import com.itextpdf.text.Paragraph;  
import com.itextpdf.text.Phrase;  
import com.itextpdf.text.pdf.BaseFont;  
import com.itextpdf.text.pdf.PdfPCell;  
import com.itextpdf.text.pdf.PdfPTable;  
import com.itextpdf.text.pdf.PdfWriter;  

//http://blog.csdn.net/yalove/article/details/9186127  
public class zhaoPinTest {  
    public static void main(String[] args) throws DocumentException,  
            IOException {  
        // 標題字體  
        BaseFont title1 = BaseFont.createFont("c:\\windows\\fonts\\simhei.ttf",  
                BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  
        Font titleFont = new Font(title1, 25, Font.NORMAL);  
        // 設置字體  
        Font mainFont = new Font(title1, 10, Font.NORMAL);  
        float f = 0.5f;  
        Document doc = null;  
        float lineHeight = 18f;  
        PdfPCell[][] cell = new PdfPCell[100][100];  
        int colNum = 1;  
        int rowNum = 1;  
        try {  
            doc = new Document();  
            PdfWriter.getInstance(doc, new FileOutputStream("test1.pdf"));  
            doc.open();  
            Paragraph p1 = new Paragraph("招聘員工登記表\n\n", titleFont);  
            p1.setAlignment(1);  
            doc.add(p1);  
            /** 
             * 插入表格 
             */  

            /** 
             * 第一行 
             */  
            PdfPTable table = new PdfPTable(7);  
            PdfPCell cell1 = new PdfPCell(new Phrase("姓名", mainFont));  
            cell1.setUseBorderPadding(true);  
            cell1.setBorderWidth(f);  
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell1.setFixedHeight(lineHeight);  
            table.addCell(cell1);  

            PdfPCell cell2 = new PdfPCell(new Phrase(""));  
            cell2.setUseBorderPadding(true);  
            cell2.setBorderWidth(f);  
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2.setFixedHeight(lineHeight);  
            table.addCell(cell2);  

            PdfPCell cell3 = new PdfPCell(new Phrase("性別", mainFont));  
            cell3.setUseBorderPadding(true);  
            cell3.setBorderWidth(f);  
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell3.setFixedHeight(lineHeight);  
            table.addCell(cell3);  

            PdfPCell cell4 = new PdfPCell(new Phrase(""));  
            cell4.setUseBorderPadding(true);  
            cell4.setBorderWidth(f);  
            cell4.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell4.setFixedHeight(lineHeight);  
            table.addCell(cell4);  

            PdfPCell cell5 = new PdfPCell(new Phrase("出生年月", mainFont));  
            cell5.setUseBorderPadding(true);  
            cell5.setBorderWidth(f);  
            cell5.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell5.setFixedHeight(lineHeight);  
            table.addCell(cell5);  

            PdfPCell cell6 = new PdfPCell(new Phrase(""));  
            cell6.setUseBorderPadding(true);  
            cell6.setBorderWidth(f);  
            cell6.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            table.addCell(cell6);  

            PdfPCell cell7 = new PdfPCell(new Phrase("照片", mainFont));  
            cell7.setUseBorderPadding(true);  
            cell7.setBorderWidth(f);  
            cell7.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell7.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell7.setRowspan(4);  
            table.addCell(cell7);  

            /** 
             * 第二行 
             */  
            PdfPCell cell2_1 = new PdfPCell(new Phrase("學歷", mainFont));  
            cell2_1.setUseBorderPadding(true);  
            cell2_1.setBorderWidth(f);  
            cell2_1.setHorizontalAlignment(1);  
            cell2_1.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2_1.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2_1.setFixedHeight(lineHeight);  
            table.addCell(cell2_1);  

            PdfPCell cell2_2 = new PdfPCell(new Phrase(""));  
            cell2_2.setUseBorderPadding(true);  
            cell2_2.setBorderWidth(f);  
            cell2_2.setHorizontalAlignment(1);  
            cell2_2.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2_2.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2_2.setFixedHeight(lineHeight);  
            table.addCell(cell2_2);  

            PdfPCell cell2_3 = new PdfPCell(new Phrase("婚否", mainFont));  
            cell2_3.setUseBorderPadding(true);  
            cell2_3.setBorderWidth(f);  
            cell2_3.setHorizontalAlignment(1);  
            cell2_3.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2_3.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2_3.setFixedHeight(lineHeight);  
            table.addCell(cell2_3);  

            PdfPCell cell2_4 = new PdfPCell(new Phrase(""));  
            cell2_4.setUseBorderPadding(true);  
            cell2_4.setBorderWidth(f);  
            cell2_4.setHorizontalAlignment(1);  
            cell2_4.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2_4.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2_4.setFixedHeight(lineHeight);  
            table.addCell(cell2_4);  

            PdfPCell cell2_5 = new PdfPCell(new Phrase("民族", mainFont));  
            cell2_5.setUseBorderPadding(true);  
            cell2_5.setBorderWidth(f);  
            cell2_5.setHorizontalAlignment(1);  
            cell2_5.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2_5.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2_5.setFixedHeight(lineHeight);  
            table.addCell(cell2_5);  

            PdfPCell cell2_6 = new PdfPCell(new Phrase(""));  
            cell2_6.setUseBorderPadding(true);  
            cell2_6.setBorderWidth(f);  
            cell2_6.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell2_6.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell2_6.setFixedHeight(lineHeight);  
            table.addCell(cell2_6);  

            /** 
             * 第三行 
             */  
            PdfPCell cell3_1 = new PdfPCell(new Phrase("專業", mainFont));  
            cell3_1.setUseBorderPadding(true);  
            cell3_1.setBorderWidth(f);  
            cell3_1.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell3_1.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell3_1.setFixedHeight(lineHeight);  
            table.addCell(cell3_1);  

            PdfPCell cell3_2 = new PdfPCell(new Phrase(""));  
            cell3_2.setUseBorderPadding(true);  
            cell3_2.setBorderWidth(f);  
            cell3_2.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell3_2.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell3_2.setFixedHeight(lineHeight);  
            cell3_2.setColspan(2);  
            table.addCell(cell3_2);  

            PdfPCell cell3_3 = new PdfPCell(new Phrase("別業學校", mainFont));  
            cell3_3.setUseBorderPadding(true);  
            cell3_3.setBorderWidth(f);  
            cell3_3.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell3_3.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell3_3.setFixedHeight(lineHeight);  
            table.addCell(cell3_3);  

            PdfPCell cell3_4 = new PdfPCell(new Phrase(""));  
            cell3_4.setUseBorderPadding(true);  
            cell3_4.setBorderWidth(f);  
            cell3_4.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell3_4.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell3_4.setFixedHeight(lineHeight);  
            cell3_4.setColspan(2);  
            ;  
            table.addCell(cell3_4);  

            /** 
             * 第四行 
             */  
            PdfPCell cell4_1 = new PdfPCell(new Phrase("健康狀況", mainFont));  
            cell4_1.setUseBorderPadding(true);  
            cell4_1.setBorderWidth(f);  
            cell4_1.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell4_1.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell4_1.setFixedHeight(lineHeight);  
            table.addCell(cell4_1);  

            PdfPCell cell4_2 = new PdfPCell(new Phrase(""));  
            cell4_2.setUseBorderPadding(true);  
            cell4_2.setBorderWidth(f);  
            cell4_2.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell4_2.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell4_2.setFixedHeight(lineHeight);  
            cell4_2.setColspan(2);  
            table.addCell(cell4_2);  

            PdfPCell cell4_3 = new PdfPCell(new Phrase("戶籍所在地", mainFont));  
            cell4_3.setUseBorderPadding(true);  
            cell4_3.setBorderWidth(f);  
            cell4_3.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell4_3.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell4_3.setFixedHeight(lineHeight);  
            table.addCell(cell4_3);  

            PdfPCell cell4_4 = new PdfPCell(new Phrase(""));  
            cell4_4.setUseBorderPadding(true);  
            cell4_4.setBorderWidth(f);  
            cell4_4.setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell4_4.setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell4_4.setFixedHeight(lineHeight);  
            cell4_4.setColspan(2);  
            table.addCell(cell4_4);  

            /** 
             * 第五行 
             */  
            rowNum = 5;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("政治面貌", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(2);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 3;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("身份證號碼", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 4;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(3);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 第六行 
             */  
            rowNum = 6;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("工作時間", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(2);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 3;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("有無住房", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 4;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 5;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("要求待遇", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 6;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 第七行 
             */  
            rowNum = 7;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("聯系電話", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(2);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 3;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("電子郵件", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 4;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 5;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("手機", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 6;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 第八行 
             */  
            rowNum = 8;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("聯系地址", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(6);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 第九行 
             */  
            rowNum = 9;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("工作所在地", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(6);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 第十行 
             */  
            rowNum = 10;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("離職原因", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(6);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 第十一行 
             */  
            rowNum = 11;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("簡歷", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase(""));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setColspan(6);  
            table.addCell(cell[rowNum][colNum]);  

            /** 
             * 插入表格2 
             */  
            /** 
             * 第一行 
             */  
            float[] aa = new float[] { 0.06f, 0.31f, 0.31f, 0.32f };  
            PdfPTable table2 = new PdfPTable(4);  
            table2.setWidths(aa);  
            rowNum = 1;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("簡歷", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setRowspan(8);  
            table2.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("起止時間", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table2.addCell(cell[rowNum][colNum]);  

            colNum = 3;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("學習/工作單位", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table2.addCell(cell[rowNum][colNum]);  

            colNum = 4;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("專業/職位", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table2.addCell(cell[rowNum][colNum]);  

            for (int i = 2; i <= 8; i++) {  
                rowNum = 3;  
                colNum = 1;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table2.addCell(cell[rowNum][colNum]);  

                colNum = 2;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table2.addCell(cell[rowNum][colNum]);  

                colNum = 3;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table2.addCell(cell[rowNum][colNum]);  

            }  

            /** 
             * 插入表格3 
             */  
            /** 
             * 第一行 
             */  
            float[] aaa = new float[] { 0.06f, 0.31f, 0.1f, 0.1f, 0.1f, 0.33f };  
            PdfPTable table3 = new PdfPTable(6);  
            table3.setWidths(aaa);  
            rowNum = 1;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("家庭情況", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            cell[rowNum][colNum].setRowspan(6);  
            table3.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("姓名", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table3.addCell(cell[rowNum][colNum]);  

            colNum = 3;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("關系", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table3.addCell(cell[rowNum][colNum]);  

            colNum = 4;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("年齡", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table3.addCell(cell[rowNum][colNum]);  

            colNum = 5;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("文化程度", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table3.addCell(cell[rowNum][colNum]);  

            colNum = 6;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("現工作單位", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(lineHeight);  
            table3.addCell(cell[rowNum][colNum]);  

            for (int i = 2; i <= 6; i++) {  
                rowNum = i;  
                colNum = 1;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table3.addCell(cell[rowNum][colNum]);  

                colNum = 2;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  

                table3.addCell(cell[rowNum][colNum]);  

                colNum = 3;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table3.addCell(cell[rowNum][colNum]);  

                colNum = 4;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table3.addCell(cell[rowNum][colNum]);  

                colNum = 5;  
                cell[rowNum][colNum] = new PdfPCell(new Phrase("", mainFont));  
                cell[rowNum][colNum].setUseBorderPadding(true);  
                cell[rowNum][colNum].setBorderWidth(f);  
                cell[rowNum][colNum]  
                        .setHorizontalAlignment(Element.ALIGN_CENTER);  
                cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
                cell[rowNum][colNum].setFixedHeight(lineHeight);  
                table3.addCell(cell[rowNum][colNum]);  
            }  

            /** 
             * 插入表格4 
             */  
            /** 
             * 第一行 
             */  
            float[] aaaa = new float[] { 0.06f, 0.94f };  
            PdfPTable table4 = new PdfPTable(2);  
            table4.setWidths(aaaa);  
            rowNum = 1;  
            colNum = 1;  
            cell[rowNum][colNum] = new PdfPCell(new Phrase("特別提示", mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_CENTER);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(50f);  
            table4.addCell(cell[rowNum][colNum]);  

            colNum = 2;  
            cell[rowNum][colNum] = new PdfPCell(  
                    new Phrase(  
                            "   1. 本人承諾保證所填寫資料真實。\n   2. 保證遵守公司招聘有關規程和國家有關法規\n   3. 請填寫好招聘登記表,帶齊照片、學歷、職稱證書的有效證件及相關復印件。",  
                            mainFont));  
            cell[rowNum][colNum].setUseBorderPadding(true);  
            cell[rowNum][colNum].setBorderWidth(f);  
            cell[rowNum][colNum].setHorizontalAlignment(Element.ALIGN_LEFT);  
            cell[rowNum][colNum].setVerticalAlignment(Element.ALIGN_MIDDLE);  
            cell[rowNum][colNum].setFixedHeight(100f);  
            table4.addCell(cell[rowNum][colNum]);  

            doc.add(table);  
            doc.add(table2);  
            doc.add(table3);  
            doc.add(table4);  

        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        } finally {  
            doc.close();  
        }  
    }  
}  </pre> 


 本文由用戶 gbd8 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!