java.lang.ClassNotFoundException: org.apache.poi.xwpf.usermodel.IRunBody

6.8k Views Asked by At

I am trying to convert docx to pdf using xdocreport but I end up with classnot found exception for the class IRunBody. My package 'org.apache.poi.xwpf.usermodel' doesnt seem to have this interface. I have all the required jars for this. poi, poi-ooxml, poi-ooxml-schemas and yet I am unable to get this class. Can anyone let me know what am I missing here? Any other jars that I need to add? Below is the code that I am runnig

        XWPFDocument xwpfDoc = new XWPFDocument(new FileInputStream(fileName));
        PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
        String randomFilename = UUID.randomUUID().toString();
        String outputFIlePath = TEMPORARY_PDF_FILE_LOCATION + randomFilename + ".pdf";
        OutputStream output = new FileOutputStream(outputFIlePath);
        PdfConverter.getInstance().convert(xwpfDoc, output, options);
2

There are 2 best solutions below

0
On

My ooxml jar was not latest. After updating ooxml jar, the issue was resolved. Thank you.

0
On

I had exactly same problem. And I resolved it!

Because my project is not Maven, I could not use nice Dependencies maven resolver - what I did is 1) just temporary I created new empty Maven project; 2) in pom.xml I add just these 3 required for my needs libraries:

  <dependencies>
    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>org.apache.poi.xwpf.converter.core</artifactId>
        <version>1.0.5</version>
    </dependency>

    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
        <version>1.0.5</version>
    </dependency>

    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>
        <version>1.0.5</version>
    </dependency>

  </dependencies> 

3) Updated this Maven project, so it downloaded all these libraries and all of its dependencies, so I have got this jars:

enter image description here 4) Then just copied these jars to my real project and it worked!

I recommend you to do same thing, instead of trying to solve dependencies manually.