我想使用PdfPTable创建一个表单,如下所示:
如何在iTextPdf中调整PdfPCell内的PdfPTable?
我尝试使用以下代码但未成功:
Orders listOrders = (Orders) model.get("listOrders");
PdfContentByte pdfContentByte = writer.getDirectContent();
Barcode128 barcode128 = new Barcode128();
barcode128.setCodeType(Barcode128.CODE128);
barcode128.setCode(listOrders.getGenerated_orderID());
Image codeEANImage = barcode128.createImageWithBarcode(pdfContentByte, null, null);
codeEANImage.scalePercent(100);
Font font = FontFactory.getFont(FontFactory.HELVETICA);
font.setColor(BaseColor.BLACK);
font.setSize(8);
Image image = Image.getInstance(logo);
Paragraph paragraph = new Paragraph("some text",font);
paragraph.setAlignment(ALIGN_CENTER);
document.add(paragraph);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(80);
table.setWidths(new int[]{1, 1, 1});
PdfPCell pdfPCell = new PdfPCell();
pdfPCell.setImage(image);
image.scalePercent(10);
table.addCell(pdfPCell);
table.addCell(codeEANImage);
table.addCell(listOrders.getSender_address());
PdfPTable tableLeft = new PdfPTable(2);
tableLeft.setWidthPercentage(40);
tableLeft.setWidths(new int[]{1, 1});
tableLeft.getDefaultCell().setBorder(Rectangle.NO_BORDER);
PdfPCell leftLabel = new PdfPCell(new Phrase("Sender",font));
leftLabel.setColspan(2);
tableLeft.addCell(leftLabel);
tableLeft.addCell(new Phrase("Person:",font));
tableLeft.addCell(new PdfPCell(new Phrase(listOrders.getPersonality(),font))).setBorder(Rectangle.BOX);
PdfPTable tableRight = new PdfPTable(2);
tableRight.setWidthPercentage(40);
tableRight.setWidths(new int[]{1, 1});
tableRight.getDefaultCell().setBorder(Rectangle.NO_BORDER);
PdfPCell rightLabel = new PdfPCell(new Phrase("Rec:",font));
rightLabel.setColspan(2);
tableRight.addCell(rightLabel);
tableRight.addCell(new Phrase("Name:",font));
tableRight.addCell(new PdfPCell(new Phrase(listOrders.getReceiver_firstname(),font))).setBorder(Rectangle.BOX);
table.addCell(tableLeft);
table.addCell(tableRight);
table.setSpacingBefore(0);
document.add(table);
有人可以建议我如何构建它吗?