嘗試使用iText進行簡單的PDF生成,並在表格元素上遇到NotImplementedException。iText - com.itextpdf.tool.xml.exceptions.NotImplementedException
TableRowElement.type()只是拋出new NotImplementedException()...爲什麼它被稱爲?
com.itextpdf.tool.xml.exceptions.NotImplementedException
at com.itextpdf.tool.xml.html.table.TableRowElement.type(TableRowElement.java:148)
at com.itextpdf.text.pdf.ColumnText.addElement(ColumnText.java:471)
at com.itextpdf.text.pdf.PdfPCell.addElement(PdfPCell.java:284)
at com.itextpdf.tool.xml.html.table.TableData.end(TableData.java:151)
at com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:189)
at com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:206)
at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:141)
at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:395)
at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:70)
at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:235)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:213)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:175)
at com.slim.pims.upload.ui.OwnerMainPDF.doPost(OwnerMainPDF.java:90)
at com.slim.pims.upload.ui.OwnerMainPDF.doGet(OwnerMainPDF.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
來源:
//now, this is fun!
public boolean process(final ElementListener listener) {
throw new NotImplementedException();
}
public int type() {
throw new NotImplementedException();
}
public boolean isContent() {
throw new NotImplementedException();
}
public boolean isNestable() {
throw new NotImplementedException();
}
public List<Chunk> getChunks() {
throw new NotImplementedException();
}
編輯,包括html源代碼。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table style="width: 100%; ">
<tr>
<td>
<tr>
<td align="left" width="40%" valign="top">
<table id='tableRegionTotals' style='width: 100%;' border='0' cellpadding='0' cellspacing='1' bgcolor='#cccccc'><tr height='20'><td class='a5' align='center' width=40%;><stong>Schedule Status</stong></td><td class='a5' align='center' width=30%;><stong>No.</stong></td><td class='a5' align='center' width=30%;><stong>Total (for New Projects)</stong></td></tr><tr height='20'><td class='a0' align='left'><table><tr><td width=10%;> </td><td class='a0' width=90%;><div id='divOnTrack' style='width:10px;background-color:#336633;' > <a onclick='' name='nontrack'>On Track </a></div></td></tr></table></td><td class='a0' align='right'>1 </td><td class='a0' align='right'>0.00 </td></tr><tr height='20'><td class='a0' align='left'><table><tr><td width=10%;> </td><td class='a0' width=90%;><div id='divNeedsAttention' style='width:10px;background-color:#cccc33;' > <a onclick='' name='nontrack'>Needs Attention </a></div></td></tr></table></td><td class='a0' align='right'>1 </td><td class='a0' align='right'>0.00 </td></tr><tr height='20'><td class='a0' align='left'><table><tr><td width=10%;> </td><td class='a0' width=90%;><div id='divOffTrack' style='width:10px;background-color:#cc0000;' > <a onclick='' name='nontrack'>Off Track </a></div></td></tr></table></td><td class='a0' align='right'>20 </td><td class='a0' align='right'>0 </td></tr></table>
</td>
<td width="1%"> </td>
<td align="right" width="55%" valign="top">
</td>
</tr>
</td>
</tr>
</table>
<table>
<tr>
<td>
</td>
</tr>
</table>
</body>
</html>
在iText中創建表格時,不需要行。你創建一個'PdfPTable'並添加'PdfPCell'實例。行的概念只存在於內部。爲了清楚起見,你提到的'Element'接口的方法會拋出'NotImplementedException'。 AFAIK,從來沒有人提出過需要'type()'方法的用例。 –
我通過調用parseXHtml(PdfWriter writer,Document doc,Reader in)得到了這個錯誤;也parseXHtml(PdfWriter作家,Document doc,InputStream in,InputStream inCssFile)。所以type()被其他iText API內部調用。 – wez
啊哈,那是有趣的信息。只要您讓我知道您使用的是哪個版本,我就會將它傳遞給XML Worker的開發人員。我還需要一個可用於重現錯誤的HTML文件(該錯誤從未在我們的JUnit測試中拋出)。 –