0

我在生成 PDF 时使用表中的表,但出现以下错误。

com.ost.radhaz.struts.survey.action.PreviewSurveyAction caught an exception: com.lowagie.text.BadElementException

com.lowagie.text.BadElementException: ***Adding a cell at the location (4,1) with a colspan of 1 and a rowspan of 1 is illegal (beyond boundaries/overlapping).***
                at com.lowagie.text.Table.addCell(Unknown Source)
                at com.ost.radhaz.struts.survey.action.PreviewSurveyAction.generatePDFDocumentBytes(PreviewSurveyAction.java:882)
                at com.ost.radhaz.struts.survey.action.PreviewSurveyAction.execute(PreviewSurveyAction.java:81)
                at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
                at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
                at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
                at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
                at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
                at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:182)
                at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:644)
                at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)
                at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:908)
                at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)
                at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:226)
                at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:127)
                at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:116)
                at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
                at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
                at java.lang.Thread.run(Unknown Source)

我在网上查找发现 iText 不再使用表格,他们建议使用 PDFPTable。显然,对于在我的代码中使用表中表的代码量,我尝试仅使用一段代码来查看 PDFPtable 是否生成 PDF。显然不是,我能够克服上述错误,但我用来显示特定文本块的 PDFPcell 没有显示出来。它显示为空。请指教。

下面是我用于 PDFPcell 的代码

Phrase p2 = new Phrase("This is test phrase2", FontFactory.getFont(FontFactory.COURIER, 30, Font.NORMAL, new Color(255, 0, 0)));
PdfPCell test2 = new PdfPCell(p2);
optable.addCell(test2);

上面的这个短语没有出现在我的 PDF 中,它显示为空,即使我必须生成 PDF

请注意,在我上面使用的代码块中 optable 是 PDFPtable,它再次嵌入在表中(不是 PDFPtable)。

4

0 回答 0