在 PdfPCell 中,我想放置多个图像,并在每个图像下方放置一个文本。我试过这段代码:
private PdfPTable tabellaRighe() throws BadElementException, MalformedURLException, IOException, DocumentException {
int[] cellWidth = {500, 95};
PdfPTable table = new PdfPTable(2);
table.setWidths(cellWidth);
table.setTotalWidth(PageSize.A4.getWidth() - 45);
table.setLockedWidth(true);
PdfPCell cell;
cell = new PdfPCell();
cell.setBorderWidth(0);
Paragraph p = new Paragraph();
for (int i = 0; i < 4; i++) {
Image image = Image.getInstance(imgNd);
image.scaleToFit(300, 135);
Phrase ph = new Phrase();
ph.add(new Chunk(image, 0, 0, true));
ph.add("CIAO");
p.add(ph);
}
cell.addElement(p);
table.addCell(cell);
cell = new PdfPCell();
cell.setBorderWidthBottom(1);
cell.setBorderWidthLeft(1);
cell.setBorderWidthRight(1);
cell.setBorderWidthTop(1);
table.addCell(cell);
}
但文字不在图像下方,而是向右移动。如何将文字放在每张图片下方?