title: Word document to PDF conversion with docx4j
body: <p>I'm trying to convert a docx file to pdf, docx is a template with header, text and pictures that has been edited through docx4j. This is the piece of code for conversion...</p>
  
  <pre><code>private static void wordClientToPDF() throws FileNotFoundException, IOException
  {
      try {
  
          // 1) Load DOCX into WordprocessingMLPackage
          InputStream is = new FileInputStream(new File(WORD_FILE_PATH_CLIENT));
          WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
  
          // 2) Prepare Pdf settings
          PdfSettings pdfSettings = new PdfSettings();
  
          // 3) Convert WordprocessingMLPackage to Pdf
          OutputStream out = new FileOutputStream(new File(PDF_FILE_PATH_CLIENT));
          PdfConversion converter = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
          converter.output(out, pdfSettings);
  
      } catch (Throwable e) {
          //YURY: print stack trace in message
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          e.printStackTrace(pw);
          sw.toString(); // stack trace as a string
          javax.swing.JOptionPane.showMessageDialog(panel, "PDF conversion error: " + sw.toString());
      }
  }
  </code></pre>
  
  <p>However, I'm receiving the following error <img src="https://i.stack.imgur.com/JZHFI.png" alt="DocxToPdfConversionError"></p>
  
  <p>Any help is appreciated.</p>