Itext生成的pdf在打开时抛出错误

时间:2014-07-25 08:29:19

标签: java pdf pdf-generation adobe itext

我正在使用itext pdf版本5.3.4。直到最近代码工作正常但客户端需要一些修改,现在当打开生成的pdf时,显示以下错误" "此页面上存在错误。 Acrobat可能无法正确显示页面。请联系创建pdf文档的人来解决问题"。

我将把我认为错误的代码放在下面,并稍微解释一下。基本上我有一系列我正在迭代的行,我希望内容能够显示出来(这就是我使用generalTable变量的原因)。以下是代码,如果我能再给您详细信息,请告诉我们:

            PdfPTable generalTable = new PdfPTable(2);
            generalTable.setKeepTogether(true);
            generalTable.setWidthPercentage(100);
            Iterator rows = objects.iterator();
            String ratingCellText = "";
            while (rows.hasNext()) {
                SupplierSearchRecord rec = (SupplierSearchRecord)rows.next();
                if (rec.getMgID() == mgVO.getId() &&
                        rec.getGaID() == gzVO.getId()) {
                    String cellText = "";
                    if (company != rec.getCompanyId()) {
                        if (ratingCellText.length() > 0) {
                            PdfPCell myCell1 = PdfUtil.makeCell(simpleFont, PdfUtil.getText(ratingCellText));
                            myCell1.setBorder(Rectangle.TOP);
                            myCell1.setColspan(2);
                            generalTable.addCell(myCell1);
                            ratingCellText = "";
                        }
                        generalTable.addCell(PdfUtil.makeCell(simpleFont, PdfUtil.getText("\n\n" + rec.getCompanyTitle())));
                        String duns = "\n\n" + ((isNotEmpty(rec.getCompanyDuns()))?txtUtil.msg("optioncompanyDuns")+": ":"") +
                                   PdfUtil.getText(rec.getCompanyDuns()) ;
                        generalTable.addCell(PdfUtil.makeCell(simpleFont, duns));

                        String tel = ((isNotEmpty(rec.getCompanyPhone1()))?"    Tel: ":"") +
                                   PdfUtil.getText(rec.getCompanyPhone1()) +
                                  ((isNotEmpty(rec.getCompanyPhone1()))?", ":"") ;
                        String fax = ((isNotEmpty(rec.getCompanyFax()))?"Fax: ":"") +
                                   PdfUtil.getText(rec.getCompanyFax()) +
                                  ((isNotEmpty(rec.getCompanyFax()))?", ":"") ;
                        String homePage = ((isNotEmpty(rec.getCompanyInternetAddress()))?txtUtil.msg("optioncompanyInternetAddress")+": ":"") +
                                           PdfUtil.getText(rec.getCompanyInternetAddress()) +
                                          ((isNotEmpty(rec.getCompanyInternetAddress()))?", ":"") ;
                        String email = ((isNotEmpty(rec.getCompanyEmail()))?"Email: ":"") +
                                   PdfUtil.getText(rec.getCompanyEmail()) +
                                  ((isNotEmpty(rec.getCompanyEmail()))?", ":"") ;

                        cellText = "\n" + PdfUtil.getText(rec.getCompanyAddress()) + ", " + PdfUtil.getText(rec.getCompanyPostalCode()+ ", " + rec.getCompanyCity() + ", " + rec.getCompanyCountryTitle()) + "\n" +
                                            tel +
                                            fax +
                                            homePage +
                                            email;
                        PdfPCell myCell = PdfUtil.makeCell(simpleFont, PdfUtil.getText(cellText));
                        myCell.setBorder(Rectangle.BOTTOM);
                        myCell.setColspan(2);
                        generalTable.addCell(myCell);
                    }
                    company = rec.getCompanyId();
                    document.add(generalTable);
                    generalTable.deleteBodyRows();

谢谢和最诚挚的问候。

0 个答案:

没有答案