itext pdf及其下面的图像和文本列表
需要帮助生成一个pdf,其中包含描述其下图像的图像和文本列表 尝试了以下操作,但图像和文本并排显示。请帮我做这个。谢谢itext pdf及其下面的图像和文本列表,pdf,itext,Pdf,Itext,需要帮助生成一个pdf,其中包含描述其下图像的图像和文本列表 尝试了以下操作,但图像和文本并排显示。请帮我做这个。谢谢 ........ PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSplitRows(true); table.setWidthPercentage(90f); Paragraph paragraph = new Paragrap
........
PdfPTable table = new PdfPTable(1);
table.setHorizontalAlignment(Element.ALIGN_CENTER);
table.setSplitRows(true);
table.setWidthPercentage(90f);
Paragraph paragraph = new Paragraph();
for (int counter = 0; counter < empSize; counter++) {
String imgPath = ... ".png");
Image img = Image.getInstance(imgPath);
img.scaleAbsolute(110f, 95f);
Paragraph textParagraph = new Paragraph("Test" + counter));
textParagraph.setLeading(Math.max(img.getScaledHeight(), img.getScaledHeight()));
textParagraph.setAlignment(Element.ALIGN_CENTER);
Phrase imageTextCollectionPhase = new Phrase();
Phrase ph = new Phrase();
ph.add(new Chunk(img, 0, 0, true));
ph.add(textParagraph);
imageTextCollectionPhase.add(ph);
paragraph.add(imageTextCollectionPhase);
}
PdfPCell cell = new PdfPCell(paragraph);
table.addCell(cell);
doc.add(table);
。。。。。。。。
PdfPTable table=新的PdfPTable(1);
表.设置水平对齐(元素.对齐\中心);
表3.setSplitRows(真);
表2.设置宽度百分比(90f);
段落=新段落();
对于(int counter=0;counter
我假设您希望得到如下结果:
PdfPCell cell = new PdfPCell();
cell.addElement(img1);
cell.addElement(new Paragraph("Brazil"));
table.addCell(cell);
在本例中,您将所有内容(所有图像和所有文本)添加到单个单元格中。应将它们添加到单独的单元格中,如示例所示:
您可以轻松地更改此概念证明,以便使用循环。只需确保将addCell()
方法放在循环内部,而不是循环外部
您还可以显式创建一个PdfPCell
,并在同一单元格中组合文本和图像,如下所示:
PdfPCell cell = new PdfPCell();
cell.addElement(img1);
cell.addElement(new Paragraph("Brazil"));
table.addCell(cell);
为什么要将所有内容添加到单个单元格中?如果只使用ine单元格,创建表有什么意义?将图像和文本添加到单独的单元格中。