2015-08-20 98 views
3

我想創建一個包含點列表的表格。我不會提前知道我有多少個點,但是如果它們溢出了單元格,我想讓它們換行,就像文本一樣。我的代碼是這樣的:iText:單元格中的圖像列表

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個點大概是其他的一半。

(我想張貼圖片,但我沒有足夠的老將在這個網站。)

有沒有一種方法,使所有圖像大小相同?

回答

1

請看看ImagesInChunkInCell的例子。我拿了一個燈泡的形象,而不是子彈。我能夠重現您所描述的問題,但你可以在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); 

這防止圖像被縮放。

相關問題