需要帮助生成一个 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) 使用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)