清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
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(); } } }