简体   繁体   English

iText:单元格中的图像列表

[英]iText: List of images in a cell

I would like to create a table that has a list of dots. 我想创建一个包含点列表的表。 I don't know ahead of time how many dots I have, but if they overflow the cell, I want them to wrap, just like text would. 我事先不知道我有多少个点,但是如果它们溢出单元格,我希望它们像文本一样包裹起来。 My code is something like this: 我的代码是这样的:

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);

The dots wrap, like I expect, but they don't all have the same size. 像我期望的那样,点包起来,但是它们的大小并不相同。 There are 7 rows of 5 dots each, and all 35 dots have the same size. 有7行,每行5个点,所有35个点的大小相同。 The last row of 5 dots are roughly half the size of the others. 最后一行的5个点大约是其他大小的一半。

(I tried to post an image, but I'm not veteran enough on this site.) (我试图发布图片,但是我在此网站上经验不足。)

Is there a way to make all the images the same size? 有没有办法使所有图像大小相同?

Please take a look at the ImagesInChunkInCell example. 请看一下ImagesInChunkInCell示例。 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 , I was able to add one extra line: 我能够重现您描述的问题,但是正如您在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);

The extra line is: 额外的一行是:

image.setScaleToFitHeight(false);

This prevents that the image is scaled. 这样可以防止图像缩放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM