//生成PDF开始
Document document = new Document(PageSize.A4, -10f, -10f, 144f, 56f);//设置页大小A4,也边距(左右,上下)
PdfWriter out = PdfWriter.getInstance(document, new FileOutputStream("e:\\test.pdf"));
BaseFont bfChinese = BaseFont.createFont("C:\\Windows\\Fonts\\SIMSUN.TTC,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//宋体
Font FontChinese = new Font(bfChinese, 12, Font.BOLD);
PdfPTable mainTable = new PdfPTable(1);// 大表格一列
mainTable.setSplitLate(false);//跨页处理
mainTable.setSplitRows(true);
PdfPCell cellMain = new PdfPCell(new Paragraph("偿还指数", FontChinese));// 第一列,创建单元格cell
cellMain.setHorizontalAlignment(positionLeft);//水平居右
cellMain.setBackgroundColor(skyColor);//单元格背景颜色,我设置的是 BaseColor skyColor = new BaseColor(224, 234, 239); 背景颜色天蓝色
cellMain.setBorderWidth(7f);//边框7px
cellMain.setFixedHeight(30);//单元格高30px
cellMain.setBorderColor(skyColor);//边框颜色
mainTable.addCell(cellMain);//添加到table去,每创一个cell,都添加到table才有效。
//第二行
//偿还指数信息的cell-----begin------
PdfPCell repayCell = new PdfPCell();
repayCell.setBorderWidth(7f);
repayCell.setBorderColor(grayLableColor);
repayCell.setPaddingLeft(-45f);
repayCell.setPaddingTop(10f);
repayCell.setPaddingBottom(10f);
repayCell.setPaddingRight(-45f);
repayCell.setBackgroundColor(whiteColor);
// 偿还指数信息的表格(嵌入表格)----begin---
PdfPTable repayTable = new PdfPTable(4);//一行四列(column,row);
repayTable.setWidths(new float[]{0.18f,0.4f,0.16f,0.26f});//每个单元格占多宽
PdfPCell cell = new PdfPCell();//创建单元格
cell.setColspan(4);//跨4列
//加载图片
Image image = Image.getInstance(imagePath+"/images/pic/pic_"+isIndex(repayIndexInfo.getScore())+".jpg");
cell.setImage(image);
cell.setBorderColor(whiteColor);//设置背景颜色,我这里是白色 BaseColor whiteColor = new BaseColor(255, 255, 255);
repayTable.addCell(cell);//table加入单元格
cell = new PdfPCell(new Paragraph("企业偿还指数:", FontChinese2));
cell.setHorizontalAlignment(positionLeft);
cell.setVerticalAlignment(positionTop);//垂直居上int positionTop = Element.ALIGN_TOP;
cell.setBorderWidth(1f);
cell.setBorderColor(whiteColor);
cell.setFixedHeight(20);
cell.setBackgroundColor(grayLableColor);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph("$ 700.00", FontChinese2));
cell.setHorizontalAlignment(positionLeft);
cell.setBorderWidth(1f);
cell.setBorderColor(whiteColor);
cell.setColspan(3);
cell.setBackgroundColor(grayContentColor);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph("信用风险评级:", FontChinese2));
cell.setHorizontalAlignment(positionLeft);
cell.setVerticalAlignment(positionTop);
cell.setBorderWidth(1f);
cell.setFixedHeight(20);
cell.setBorderColor(whiteColor);
cell.setBackgroundColor(grayLableColor);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph(isString(repayIndexInfo.getRiskAssessment()), FontChinese2));
cell.setHorizontalAlignment(positionLeft);
cell.setBorderWidth(1);
cell.setBorderColor(whiteColor);
cell.setColspan(3);
cell.setBackgroundColor(grayContentColor);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph("建议信用额度:", FontChinese2));
cell.setHorizontalAlignment(positionLeft);
cell.setVerticalAlignment(positionTop);
cell.setBorderWidth(1f);
cell.setBorderColor(whiteColor);
cell.setFixedHeight(20);
cell.setBackgroundColor(grayLableColor);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph("目前没有具体信用额度建议", FontChinese2));
cell.setHorizontalAlignment(positionLeft);
cell.setBorderWidth(1);
cell.setBorderColor(whiteColor);
cell.setColspan(3);
cell.setBackgroundColor(grayContentColor);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph("注释: 企业偿还指数是判断目标企业偿还付款能力的早期指针,指数越高,拖欠款风险可能越高。企业偿还指数从100分最好的评级",FontChinese3));
cell.setColspan(4);
cell.setBorderWidth(1f);
cell.setBorderColor(whiteColor);
cell.setFixedHeight(12);
repayTable.addCell(cell);
cell = new PdfPCell(new Paragraph(" 到600分最高风险。",FontChinese3));
cell.setColspan(4);
cell.setBorderWidth(1f);
cell.setBorderColor(whiteColor);
cell.setFixedHeight(12);
repayTable.addCell(cell);
// 基本信息的表格-----end-----
repayCell.addElement(repayTable);
// 基本信息的单元格-----end-----
mainTable.addCell(repayCell);//把mainTable 第2行的单元格加进去
document.add(mainTable);
//把table加入到document对象里
document.close();

这里是截取我项目部分内容,整理了一下。可能有些地方不对。可以给我留言,到时候修改过来。最近一直在研究Itext,如果可以大家一起讨论。