title: Apache PDFBox refuses to open temporary created PDF file
body: <p>I am creating desktop JavaFX application for viewing PDF files. PDFs are at resource folder. I read resourse file as stream, then I create temporary file and use it to convert contents to image and show into ImageView.</p>
  
  <pre><code>       currentPdf =  new File("current.pdf");
          if (!currentPdf.exists()) {
              // In JAR
              InputStream inputStream = ClassLoader.getSystemClassLoader()
                      .getResourceAsStream("PDFSample.pdf");
              // Copy file
              OutputStream outputStream;
              try {
                  outputStream = new FileOutputStream(currentPdf);
              } catch (FileNotFoundException e) {
                  throw new RuntimeException(e);
              }
              byte[] buffer = new byte[1024];
              int length;
              try {
                  while ((length = inputStream.read(buffer)) &gt; 0) {
                      outputStream.write(buffer, 0, length);
                  }
                  outputStream.close();
                  inputStream.close();
              } catch(IOException e) {
                  throw new RuntimeException(e);
              }
          }
  </code></pre>
  
  <p>The problem is: when I create regular file with</p>
  
  <pre><code>currentPdf =  new File("current.pdf");
  </code></pre>
  
  <p>Everything works as expected (i get <code>current.pdf</code> created at directory where <code>jar</code> is located). But I want the file to be created at system temp folder and to be deleted on exit from application. I tried this:</p>
  
  <pre><code>try {
      currentPdf =  File.createTempFile("current",".pdf");
  } catch (IOException e) {
      throw new RuntimeException(e);
  }
  currentPdf.deleteOnExit();//also tried to comment this line
  </code></pre>
  
  <p>And get exception:</p>
  
  <pre><code>Caused by: java.io.IOException: Error: End-of-File, expected line
      at org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1517)
      at org.apache.pdfbox.pdfparser.PDFParser.parseHeader(PDFParser.java:360)
      at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:186)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1227)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1194)
      at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1165)
      at ua.com.ethereal.pdfquiz.Controller.getPdfPageAsImage(Controller.java:147)
  </code></pre>
  
  <p>At this method:</p>
  
  <pre><code>@SuppressWarnings("unchecked")
  public static Image getPdfPageAsImage(File pdfFile, int pageNum) {
      Image convertedImage;
      try {
          PDDocument document = PDDocument.load(pdfFile);
          List&lt;PDPage&gt; list = document.getDocumentCatalog().getAllPages();
          PDPage page = list.get(pageNum);
          BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 128);
          convertedImage = SwingFXUtils.toFXImage(image, null);
          document.close();
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
      return convertedImage;
  }
  </code></pre>
  
  <p>Would appreciate help in resolving this or pointing me on way to read file directly from jar to avoid creating temporary copies.</p>