title: how to use GhostScript to convert a pdf to jpg
body: <p>It bothered me a whole day afternoon. 
  I encounter many problems and by now i cannot overcome  them.</p>
  
  <p>my code:</p>
  
  <pre><code>  public void pdf2jpg(){
      try {
          File pdfFile =new File("c://tmp//1.pdf");
          PDFDocument document = new PDFDocument();
          document.load(pdfFile); 
  
          SimpleRenderer renderer = new SimpleRenderer(); 
          renderer.setResolution(300);  
  
          List&lt;Image&gt; images = renderer.render(document); 
  
           for (int i = 0; i &lt; images.size(); i++) {  
               Image img= images.get(i);
                  ImageIO.write((RenderedImage)img, "jpg",  new File(i+".jpg"));
           } 
  
      } catch (IOException | RendererException | DocumentException e) {
          e.printStackTrace();
      }   
  
    }
  </code></pre>
  
  <p>My box: Windows 7, jdk:1.7.0_45(64bit), GPL ghostscript 9.0.4.
  when I use ghost4j 0.4.4, I got error "<code>net.sf.ghost4j.renderer.RendererException: net.sf.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -20</code>" </p>
  
  <p>on <code>List&lt;Image&gt; images = renderer.render(document);</code></p>
  
  <p>Some thread here mentions it's about ghost4j version. so i change to 0.4.6, <code>error 20</code> disappears, but comes <code>Warning:  An error occurred while reading an XREF table.</code> on the same sentence.</p>
  
  <p>I cannot figure out  how to get out of this 'mud',  </p>
  
  <p>Thanks very much for your help.</p>