iText:单元格中的图像列表
iText: List of images in a cell
我想创建一个包含点列表的 table。我事先不知道我有多少个点,但如果它们溢出单元格,我希望它们像文本一样换行。我的代码是这样的:
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(new float[]{80});
table.setLockedWidth(true);
Phrase listOfDots = new Phrase();
for (int i = 0; i < 40; i++) {
listOfDots.add(new Chunk(pdf.correct, 0, 0));
listOfDots.add(new Chunk(" "));
}
table.addCell(listOfDots);
outerCell.addElement(table);
圆点如我所料,但它们的大小并不完全相同。有 7 行,每行 5 个点,所有 35 个点的大小相同。最后一行的 5 个点大约是其他点的一半大小。
(我尝试 post 图片,但我在这个网站上还不够老手。)
有没有办法让所有的图片大小一样?
请看一下 ImagesInChunkInCell example. Instead of a bullet, I took the image of a light bulb. I was able to reproduce the problem you described, but as you can see in list_with_images.pdf,我可以添加一行:
Image image = Image.getInstance(IMG);
image.setScaleToFitHeight(false);
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(new float[]{120});
table.setLockedWidth(true);
Phrase listOfDots = new Phrase();
for (int i = 0; i < 40; i++) {
listOfDots.add(new Chunk(image, 0, 0));
listOfDots.add(new Chunk(" "));
}
table.addCell(listOfDots);
额外的一行是:
image.setScaleToFitHeight(false);
这可以防止图像被缩放。
我想创建一个包含点列表的 table。我事先不知道我有多少个点,但如果它们溢出单元格,我希望它们像文本一样换行。我的代码是这样的:
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(new float[]{80});
table.setLockedWidth(true);
Phrase listOfDots = new Phrase();
for (int i = 0; i < 40; i++) {
listOfDots.add(new Chunk(pdf.correct, 0, 0));
listOfDots.add(new Chunk(" "));
}
table.addCell(listOfDots);
outerCell.addElement(table);
圆点如我所料,但它们的大小并不完全相同。有 7 行,每行 5 个点,所有 35 个点的大小相同。最后一行的 5 个点大约是其他点的一半大小。
(我尝试 post 图片,但我在这个网站上还不够老手。)
有没有办法让所有的图片大小一样?
请看一下 ImagesInChunkInCell example. Instead of a bullet, I took the image of a light bulb. I was able to reproduce the problem you described, but as you can see in list_with_images.pdf,我可以添加一行:
Image image = Image.getInstance(IMG);
image.setScaleToFitHeight(false);
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(new float[]{120});
table.setLockedWidth(true);
Phrase listOfDots = new Phrase();
for (int i = 0; i < 40; i++) {
listOfDots.add(new Chunk(image, 0, 0));
listOfDots.add(new Chunk(" "));
}
table.addCell(listOfDots);
额外的一行是:
image.setScaleToFitHeight(false);
这可以防止图像被缩放。