小编use*_*541的帖子

itext pdf,下面包含图像和文本列表

需要帮助生成一个 pdf,其中包含图像列表和描述图像的文本。

尝试了下面的方法,但将图像和文本放在一起。请在这方面需要帮助。谢谢。

........

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);
Run Code Online (Sandbox Code Playgroud)

pdf itext

2
推荐指数
1
解决办法
2091
查看次数

避免多个if/else条件

使用java 6

要检查70多个属性,如下所示.重构代码的最佳方法是什么?

    if(0 == compareField1) {            
        if(0 == compareField2) {
            if(0 == compareField3) {
                if(0 == compareField4) {
                    if(0 == compareField5) {
                        ......
                    } else {
                        return compareField5;
                    }
                } else {
                    return compareField4;
                }
            } else {
                return compareField3;
            }               
        } else {
            result = compareField2;
        }           
    } else {
        result = compareField1;
    }
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
91
查看次数

标签 统计

itext ×1

java ×1

pdf ×1