opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.23k stars 375 forks source link

ArrayIndexOutOfBoundsException: converting .docx tables to pdf #360

Open AndrewLubanec opened 5 years ago

AndrewLubanec commented 5 years ago

Hello! I'm trying to convert docx file to pdf using xwpf.converter and got this error. Debaging research stoped not itext libraries, but anyway i don't know about root cause. (example docx file see below)

    <!-- Convert Word Doc(x) to PDF -->
    <dependency>
      <groupId>fr.opensagres.xdocreport</groupId>
      <artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
      <version>2.0.2</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.xmlbeans</groupId>
          <artifactId>xmlbeans</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>3.0.2</version>
</dependency>

test

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        InputStream inputStream = ClassLoader.getSystemResourceAsStream("template.docx");

        assert inputStream != null;
        XWPFDocument wordDocument = new XWPFDocument(inputStream);
        PdfOptions options = PdfOptions.create().fontEncoding( "utf-8" );

        PdfConverter.getInstance().convert(wordDocument, outputStream, options );

    assertTrue(outputStream.size() > 0);

Trace:

fr.opensagres.poi.xwpf.converter.core.XWPFConverterException: java.lang.ArrayIndexOutOfBoundsException: 26

    at fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:71)
    at fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:39)
    at fr.opensagres.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:46)
    at org.apache.tika.server.ConvertDocxTest.convertToPdf(ConvertDocxTest.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 26
    at com.lowagie.text.pdf.PdfPRow.setWidths(Unknown Source)
    at com.lowagie.text.pdf.PdfPTable.addCell(Unknown Source)
    at fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.addCell(ExtendedPdfPTable.java:197)
    at fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.endVisitTableCell(PdfMapper.java:1327)
    at fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.endVisitTableCell(PdfMapper.java:112)
    at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitCell(XWPFDocumentVisitor.java:1148)
    at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTableRow(XWPFDocumentVisitor.java:1049)
    at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTableBody(XWPFDocumentVisitor.java:990)
    at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTable(XWPFDocumentVisitor.java:972)
    at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:267)
    at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:215)
    at fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:57)
    ... 27 more
AndrewLubanec commented 5 years ago

template (1).docx

maaoui commented 5 years ago

i am facing the same problem !