title: PDFBox Error When Converting to BufferedImage: NoClassDefFoundError: org/apache/fontbox/FontBoxFont
body: <p>I'm trying to convert a PDF doc to .png files using PDFBox.  I followed <a href="https://stackoverflow.com/questions/23326562/apache-pdfbox-convert-pdf-to-images/23327024#23327024">this answer</a> to get an idea of what dependencies were needed and to give me a starting point.  When I try to loop through the pages and create the <code>BufferedImage</code> I receive a <code>NoClassDefFoundError</code> error.  It's looking for <code>org/apache/fontbox/FontBoxFont</code> but through some extensive Googling I've not found a thing about <code>FontBoxFont</code>.  Is this a separate jar that needs to be included?  What is causing this error?  The following .jar's are included in the project:</p>
  
  <pre><code>pdfbox-2.0.2.jar
  levigo-jbig2-imageio-1.6.5.jar
  pdfbox-tools-2.0.2.jar
  jai-imageio-core-1.3.1.jar
  commons-logging-1.2.jar
  </code></pre>
  
  <p>Here is the main method:</p>
  
  <pre><code>public static void main(String[] args) {
  
      String sourceDir = "C:/Dev/Workspace/PdfToPng/Stocks.pdf";
      String destinationDir = "C:/Dev/Workspace/PdfToPng/pages/";
  
      try {
          PDDocument document = PDDocument.load(new File(sourceDir));
          PDFRenderer pdfRenderer = new PDFRenderer(document);
          for(int page = 0; page &lt; document.getNumberOfPages(); ++page) {
              BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
              ImageIOUtil.writeImage(bim, destinationDir + (page+1) + ".png", 300);
          }
          document.close();
      } catch(Exception e) {
          System.out.println(e.getStackTrace());
      }
  }
  </code></pre>
  
  <p>The error is thrown on <code>BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);</code></p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/fontbox/FontBoxFont
      at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:75)
      at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:123)
      at org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
      at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815)
      at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472)
      at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:446)
      at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
      at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:189)
      at org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:208)
      at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:139)
      at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:94)
      at PdfToPng.main(PdfToPng.java:25)
  Caused by: java.lang.ClassNotFoundException: org.apache.fontbox.FontBoxFont
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 12 more
  </code></pre>