我使用iText(5.5.8)从对象列表生成pdf。首先,我只是在列表中添加一个元素(com.itextpdf.text.List),生成的pdf非常好。
现在,我已经改进了一些pdf创建的代码,但它创建了一个空核,我只有标题(我没有修改)。
//CORE
Paragraph itin = new Paragraph();
// add a list
Paragraph list = createList(itin, listOfPackages);
// now add all this to the document
document.add(list);
document.close();
这是列表的创建
private static Paragraph createList(Paragraph paragraph, ArrayList<Package> loP) {
List list = new List(true, false, 12);
int i = 0;
while(i<loP.size()){
Paragraph info = new Paragraph();
String bufferPdf;
bufferPdf = "ICU: ";
bufferPdf = bufferPdf + loP.get(i).getIcu()+ " ";
info.add(new Paragraph(bufferPdf));
addEmptyLine(info, 1);
bufferPdf = "Adresse: ";
bufferPdf = loP.get(i).getAddress().getStreet() + ", ";
bufferPdf = bufferPdf + loP.get(i).getAddress().getNumber() + " ";
bufferPdf = bufferPdf + loP.get(i).getAddress().getBox() + ", ";
info.add(new Paragraph(bufferPdf));
bufferPdf = loP.get(i).getAddress().getPostalCode() + " ";
bufferPdf = bufferPdf + loP.get(i).getAddress().getCity() + ", ";
info.add(new Paragraph(bufferPdf));
bufferPdf = loP.get(i).getAddress().getCountry() + " ";
info.add(new Paragraph(bufferPdf));
addEmptyLine(info, 1);
bufferPdf = "Poids déclaré: ";
bufferPdf = bufferPdf + String.valueOf(loP.get(i).getWeightDecl()) + " Kg";
info.add(new Paragraph(bufferPdf));
bufferPdf = "Poids réel: ";
bufferPdf = bufferPdf + String.valueOf(loP.get(i).getRealWeight()) + " Kg";
info.add(new Paragraph(bufferPdf));
bufferPdf = "Hauteur: ";
bufferPdf = bufferPdf + String.valueOf(loP.get(i).getHeight()) + " cm";
info.add(new Paragraph(bufferPdf));
bufferPdf = "Circomférence: ";
bufferPdf = bufferPdf + String.valueOf(loP.get(i).getCircumference()) + " cm";
info.add(new Paragraph(bufferPdf));
list.add(info);
i++;
}
paragraph.add(list);
return paragraph;
}
Package列表不为空也不为null。 (它不是&#34;包&#34;来自java,Package在这里引用另一个对象。