title: Converting docx into pdf in java
body: <p>I am trying to convert a <code>docx</code> file which contains table and images into a <code>pdf</code> format file. </p>
  
  <p>I have been searching everywhere but did not get proper solution, request to give proper and correct solution:</p>
  
  <p><em>here what i have tried :</em></p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import org.apache.poi.xwpf.converter.pdf.PdfConverter;
  import org.apache.poi.xwpf.converter.pdf.PdfOptions;
  import org.apache.poi.xwpf.usermodel.XWPFDocument;
  
  public class TestCon {
  
      public static void main(String[] args) {
          TestCon cwoWord = new TestCon();
          System.out.println("Start");
          cwoWord.ConvertToPDF("D:\\Test.docx", "D:\\Test1.pdf");
      }
  
      public void ConvertToPDF(String docPath, String pdfPath) {
          try {
              InputStream doc = new FileInputStream(new File(docPath));
              XWPFDocument document = new XWPFDocument(doc);
              PdfOptions options = PdfOptions.create();
              OutputStream out = new FileOutputStream(new File(pdfPath));
              PdfConverter.getInstance().convert(document, out, options);
              System.out.println("Done");
          } catch (FileNotFoundException ex) {
              System.out.println(ex.getMessage());
          } catch (IOException ex) {
  
              System.out.println(ex.getMessage());
          }
      }
  
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.apache.poi.util.POILogger.log(ILjava/lang/Object;)V from class org.apache.poi.openxml4j.opc.PackageRelationshipCollection
  at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313)
  at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.&lt;init&gt;(PackageRelationshipCollection.java:162)
  at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.&lt;init&gt;(PackageRelationshipCollection.java:130)
  at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:559)
  at org.apache.poi.openxml4j.opc.PackagePart.&lt;init&gt;(PackagePart.java:112)
  at org.apache.poi.openxml4j.opc.PackagePart.&lt;init&gt;(PackagePart.java:83)
  at org.apache.poi.openxml4j.opc.PackagePart.&lt;init&gt;(PackagePart.java:128)
  at org.apache.poi.openxml4j.opc.ZipPackagePart.&lt;init&gt;(ZipPackagePart.java:78)
  at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:239)
  at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:665)
  at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:274)
  at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
  at org.apache.poi.xwpf.usermodel.XWPFDocument.&lt;init&gt;(XWPFDocument.java:121)
  at test.TestCon.ConvertToPDF(TestCon.java:31)
  at test.TestCon.main(TestCon.java:25)
  </code></pre>
  
  <p>My requirement is to create a java code to convert existing docx into pdf with proper format and alignment.</p>
  
  <p>Please suggest.</p>
  
  <p>Jars Used: </p>
  
  <p><a href="https://i.stack.imgur.com/Hjp2J.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Hjp2J.png" alt="Updated jars"></a></p>