gpt4 book ai didi

java - 水平分割 PDF 的一部分

转载 作者:行者123 更新时间:2023-12-02 11:30:39 25 4
gpt4 key购买 nike

Click Here for Image Reference

我正在使用 iTextG 5.5.8 和 Android。我必须将 pdf 的一部分分成两个水平 View 。我无法使用 PdfPTable 因为我想要左侧完全是图像,右侧完全是表格。另外,我必须以 25mm*12mm 尺寸呈现图像。谁能把我隐藏在实现这一目标的正确道路上?

最佳答案

有两种简单的方法可以实现这一点:

使用行跨度的一张表

假设您已将图像加载到Image image中,并添加到Document文档中:

PdfPTable table = new PdfPTable(new float[]{2,1,1});

PdfPCell imageCell = new PdfPCell(image);
imageCell.setRowspan(4);
imageCell.setVerticalAlignment(PdfPTable.ALIGN_CENTER);
table.addCell(imageCell);

PdfPCell cell = new PdfPCell(new Phrase("Address1"));
cell.setBorder(Rectangle.TOP | Rectangle.LEFT);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Contact Number"));
cell.setBorder(Rectangle.TOP | Rectangle.RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Address2"));
cell.setBorder(Rectangle.LEFT);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Fax"));
cell.setBorder(Rectangle.RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Address3"));
cell.setBorder(Rectangle.LEFT);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Pin Code"));
cell.setBorder(Rectangle.RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Address4"));
cell.setBorder(Rectangle.BOTTOM | Rectangle.LEFT);
table.addCell(cell);
cell = new PdfPCell(new Phrase(""));
cell.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
table.addCell(cell);

document.add(table);

( CreateTable 测试 testSureshOneTableRowspan)

两个表

再次假设您已将图像加载到Image image中,并将其添加到Document文档中:

PdfPTable innerTable = new PdfPTable(2);

PdfPCell cell = new PdfPCell(new Phrase("Address1"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase("Contact Number"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase("Address2"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase("Fax"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase("Address3"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase("Pin Code"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase("Address4"));
cell.setBorder(0);
innerTable.addCell(cell);
cell = new PdfPCell(new Phrase(""));
cell.setBorder(0);
innerTable.addCell(cell);

PdfPTable table = new PdfPTable(2);

PdfPCell imageCell = new PdfPCell(image);
imageCell.setVerticalAlignment(PdfPTable.ALIGN_CENTER);
table.addCell(imageCell);

table.addCell(innerTable);

document.add(table);

( CreateTable 测试 testSureshTwoTables)

关于java - 水平分割 PDF 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49319833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com