欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

openpdf

最编程 2024-10-12 11:00:08
...
String filePath = "/Users/xingyu/Documents/tmp/a.pdf"; FileOutputStream fos = new FileOutputStream(filePath); PdfWriter pdfWriter = null; Document document = null; try { document = new Document(); document.setPageSize(PageSize.A4); pdfWriter = PdfWriter.getInstance(document, fos); document.open(); Image rightTopIcon = getRightTopIcon("4"); document.add(rightTopIcon); Paragraph titleParagraph = createParagraph("新模版002", FONT_TITLE, Element.ALIGN_CENTER, 0); document.add(titleParagraph); ProcessPdfVO processPdf = new ProcessPdfVO(); processPdf.setCompanyName("xxx公司"); processPdf.setCreateTime("2024-05-27"); processPdf.setProcessId("202405270004"); processPdf.setPrintDateTime("2024-05-28 17:25:09"); processPdf.setPrinter("张三"); PdfPTable firstRow = createFirstRow(processPdf); document.add(firstRow); PdfPTable mainTable = createMainTable(); PdfPCell cell = new PdfPCell(createParagraph("审批流程", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0)); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); mainTable.addCell(cell); PdfPTable subTable = new PdfPTable(2); subTable.setWidths(new float[]{30,70}); subTable.setWidthPercentage(100); // 使得子表铺满单元格 PdfPCell subCell1 = new PdfPCell(createParagraph("subCell1", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0)); subCell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); subCell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); subCell1.setBorder(Cell.BOX); subTable.addCell(subCell1); PdfPCell subCell2 = new PdfPCell(createParagraph("subCell2", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0)); subCell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); subCell2.setBorder(Cell.BOX); subTable.addCell(subCell2); PdfPCell subCell3 = new PdfPCell(createParagraph("subCell3", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0)); subCell3.setBorder(Cell.BOX); subCell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); subTable.addCell(subCell3); PdfPCell subCell4 = new PdfPCell(createParagraph("subCell4", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0)); subCell4.setBorder(Cell.BOX); subCell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); subTable.addCell(subCell4); subTable.setComplete(true); PdfPCell subCell5 = new PdfPCell(); subCell5.setBorder(Cell.BOX); subCell5.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); subCell5.setPadding(0); subCell5.addElement(subTable); mainTable.addCell(subCell5); mainTable.addCell(new PdfPCell(createParagraph("审批流程1", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0))); mainTable.addCell(new PdfPCell(createParagraph("审批流程2", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0))); mainTable.addCell(new PdfPCell(createParagraph("审批流程3", FONT_MAIN_TABLE, Element.ALIGN_CENTER, 0))); mainTable.addCell(subCell5); mainTable.setComplete(true); document.add(mainTable); PdfPTable lastTable = createLastTable(processPdf); document.add(lastTable); } finally { IoUtil.close(document); IoUtil.close(pdfWriter); IoUtil.close(fos); }

推荐阅读