title: Convert PDF to multipage TIFF file using ghostscript in Java
body: <p>Download the Ghost libraries from <a href="http://www.ghost4j.org/downloads.html." rel="nofollow noreferrer">Ghost4j site</a>. Minimum jar required are ghost4j-1.0.0.jar, jna-3.3.0.jar, log4j-1.2.15.jar.
  Also, you have to install the Ghostscript setup, which you can find from <a href="https://www.ghostscript.com/download/gsdnld.html" rel="nofollow noreferrer">ghostscript site</a> according to your windows bit.</p>
  
  <p>Below is the code to convert the PDF to multipage TIFF.</p>
  
  <pre><code>public void PDFtoMultipageTIFFileByScript(String pdfFileLoc, String fileName, String tiffFileLoc) {
      try {
          Ghostscript gs = Ghostscript.getInstance();
          List&lt;String&gt; gsArgs = new ArrayList&lt;String&gt;();
          gsArgs.add("gswin64c.exe");
          gsArgs.add("-o");
          gsArgs.add(tiffFileLoc);
          gsArgs.add("-sDEVICE=tiffg4");
          gsArgs.add("-r600"); //Resolution.
          gsArgs.add(pdfFileLoc);
          //System.out.println("command running : " + gsArgs.toString());
  
          gs.initialize(gsArgs.toArray(new String[0]));
          gs.exit();
      } catch (GhostscriptException e) {
          System.err.println("ERROR: " + e.getMessage());
          throw new RuntimeException(e.getMessage());
      } catch (UnsatisfiedLinkError ule) {
          throw new RuntimeException(getMessage(ule.getMessage()));
      } catch (NoClassDefFoundError ncdfe) {
          throw new RuntimeException(getMessage(ncdfe.getMessage()));
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  String getMessage(String message) {
      if (message.contains("library 'gs") || message.contains("ghost4j")) {
          return message + GS_INSTALL;
      }
      return message;
  }
  </code></pre>