带有行标题colspan属性的HTML表的IText7 html2Pdf错误

时间:2017-05-31 15:48:25

标签: itext7

我正在使用iText7(html2Pdf)将HTML转换为PDF文档。当有一个包含“th”标签的表包含“colspan”属性时,该库会抛出异常。

这是我的表

<table class=" doc_table ">
    <thead class=" doc_thead ">
    <tr class=" doc_row ">
         <th align="center" class=" doc_entry " colspan="3"> <p class=" doc_p ">Instrument system </p> </th>
    </tr>
    <tr class=" doc_rowsection ">
        <th align="center" class=" doc_entry " scope="rowgroup"><p class=" doc_p ">Instrument system </p></th>
        <th align="center" class=" doc_entry " scope="rowgroup"><p class=" doc_p ">Instrument system </p></th>
        <th align="center" class=" doc_entry " scope="rowgroup"><p class=" doc_p ">Instrument system </p></th>
    </tr>
    <tr class=" doc_row ">
        <th align="left" class=" doc_entry "><p class=" doc_p ">Product </p></th>
        <th class=" doc_entry "><p class=" doc_p ">Catalog no. </p></th>
        <th class=" doc_entry "><p class=" doc_p ">Quantity </p></th>
    </tr>
    </thead>
    <tbody class=" doc_tbody ">
     //body contents
   </tbody>
</table>

例外:

Exception in thread "main" java.lang.NullPointerException
    at com.itextpdf.html2pdf.attach.wrapelement.TableWrapper.addCellToTable(TableWrapper.java:85)
    at com.itextpdf.html2pdf.attach.wrapelement.TableWrapper.addHeaderCell(TableWrapper.java:60)
    at com.itextpdf.html2pdf.attach.impl.tags.TableTagWorker.processTagChild(TableTagWorker.java:57)
    at com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:161)
    at com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:143)
    at com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:143)
    at com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:143)
    at com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.processDocument(DefaultHtmlProcessor.java:114)
    at com.itextpdf.html2pdf.attach.Attacher.attach(Attacher.java:18)
    at com.itextpdf.html2pdf.HtmlConverter.convertToDocument(HtmlConverter.java:108)
    at PdfCreator.createPdf(PdfCreator.java:58)

当从“thead”中删除第一个“tr”时,则看不到异常。当存在于“tbody”中时,相同的“tr”标签也没有抛出异常。可能是什么问题?

0 个答案:

没有答案