title: java.lang.NoSuchMethodError: org.apache.fontbox.afm.AFMParser.parse()V
body: <p>I'm having an error while using the apache PDFBox jar. It seems like somehow it is calling a method on the AFMParser class which is non-existent. AFAIK I have included fontbox properly. pdfbox,fontbox,commons and gson are all in my build path. </p>
  
  <p>I guess the error must have something to do with referencing, but this is my first JAVA project and no real clue how to debug this further. If anyone has an idea, please advice.</p>
  
  <p>Error log:</p>
  
  <pre><code>2018-03-16 14:26:50.020 java[1898:217675] java.lang.NoSuchMethodError: org.apache.fontbox.afm.AFMParser.parse()V
      at org.apache.pdfbox.pdmodel.font.PDFont.addAdobeFontMetric(PDFont.java:166)
      at org.apache.pdfbox.pdmodel.font.PDFont.addAdobeFontMetric(PDFont.java:152)
      at org.apache.pdfbox.pdmodel.font.PDFont.getAdobeFontMetrics(PDFont.java:122)
      at org.apache.pdfbox.pdmodel.font.PDFont.&lt;clinit&gt;(PDFont.java:114)
      at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:108)
      at org.apache.pdfbox.pdmodel.PDResources.getFonts(PDResources.java:213)
      at org.apache.pdfbox.util.PDFStreamEngine.getFonts(PDFStreamEngine.java:612)
      at org.apache.pdfbox.util.operator.SetTextFont.process(SetTextFont.java:69)
      at org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:562)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:269)
      at org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:236)
      at org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:216)
      at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:139)
      at org.apache.pdfbox.pdmodel.PDPage.print(PDPage.java:890)
      at java.desktop/sun.lwawt.macosx.CPrinterJob$6.run(CPrinterJob.java:757)
      at java.desktop/sun.lwawt.macosx.CPrinterJob.printAndGetPageFormatArea(CPrinterJob.java:767)
      at java.desktop/sun.lwawt.macosx.CPrinterJob.printLoop(Native Method)
      at java.desktop/sun.lwawt.macosx.CPrinterJob.print(CPrinterJob.java:334)
      at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1443)
      at org.apache.pdfbox.pdmodel.PDDocument.print(PDDocument.java:1545)
      at org.apache.pdfbox.pdmodel.PDDocument.silentPrint(PDDocument.java:1531)
      at com.xlshopgroup.printingpc.WatchFolder.printPDFFromURL(WatchFolder.java:83)
      at com.xlshopgroup.printingpc.WatchFolder.main(WatchFolder.java:118)
  Exception: Error: End-of-File, expected line
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>import java.nio.file.*;
  import java.io.*;
  import java.net.*;
  import java.nio.channels.FileChannel;
  import java.nio.ByteBuffer;
  
  import java.awt.print.PrinterJob;
  import java.awt.print.PageFormat;
  import java.awt.print.Book;
  import java.awt.print.*;
  import java.awt.print.PrinterJob;
  import javax.print.PrintService;
  
  import javax.net.ssl.HttpsURLConnection;
  
  import org.apache.pdfbox.pdmodel.PDDocument;
  import org.apache.pdfbox.pdmodel.*;   
  import org.apache.pdfbox.PrintPDF; 
  import org.apache.commons.*; 
  import org.apache.fontbox.*;
  
  import com.google.gson.*;
  
  public class WatchFolder {
  
  public static JsonObject sendPost(
          String APIURL
  ) throws Exception {
  
      String APIBASEURL = "http://example.com";
      URL obj = new URL(APIBASEURL+APIURL);
      HttpURLConnection con = (HttpURLConnection) obj.openConnection();
      //HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  
      con.setRequestMethod("POST");
  
      con.setDoOutput(true);
      DataOutputStream wr = new DataOutputStream(con.getOutputStream());
      wr.flush();
  
      BufferedReader in = new BufferedReader(
              new InputStreamReader(con.getInputStream()));
      String inputLine;
      StringBuffer response = new StringBuffer();
  
      while ((inputLine = in.readLine()) != null) {
          response.append(inputLine);
      }
      in.close();
  
      JsonObject convertedObject = new Gson().fromJson(response.toString(), JsonObject.class);
      return convertedObject;
  
  }
  
  public static void printPDFFromURL(
          String pdfURL,
          String printerName
  ) throws IOException,PrinterException {
  
      PDDocument document         = null;
  
      try {
          document = PDDocument.load(new URL(pdfURL));
          PrinterJob printJob = PrinterJob.getPrinterJob();
              printJob.setJobName(pdfURL);
  
          if(printerName != null ) {
              PrintService[] printService = PrinterJob.lookupPrintServices();
                  boolean printerFound = false;
                  for(int i = 0;!printerFound &amp;&amp; i &lt; printService.length; i++) {
                      if(printService[i].getName().indexOf(printerName) != -1) {
                          printJob.setPrintService(printService[i]);
                          printerFound = true;
                      System.out.println("Printer found: " + printService[i].getName());
                      }
                  }
          }
  
          document.silentPrint( printJob );
  
      }catch(Exception e) {
  
          System.out.println("Exception: "+e.getMessage());
  
      }finally {
  
          if(document != null) {
  
              document.close();
  
          }
  
      }
  
  }
  
  public static void main(
          String[] args
  ) throws Exception {
  
      JsonObject toBePrinted  = sendPost("gettoprint");
      JsonObject response     = toBePrinted.getAsJsonObject("response");
      JsonArray  results      = response.getAsJsonArray("results");
  
      for (JsonElement result : results) {
  
          JsonObject resultObj        = result.getAsJsonObject();
  
          String PackingSlipURL       = resultObj.get("packing_slip_url").getAsString();
          String StickerURL           = resultObj.get("sticker_url").getAsString();
          String ShippingPartner      = resultObj.get("shipping_partner").getAsString();
          String id                   = resultObj.get("id").getAsString();
  
          printPDFFromURL(PackingSlipURL, "HP-idealbetalingen-printer");
          printPDFFromURL(StickerURL, "Zebra?");
  
          //JsonObject deletedFromQueue   = sendPost("deletefromqueue/"+id);
  
      }
  
  }
  
  }
  </code></pre>