Package org.ghost4j

Class Ghostscript

java.lang.Object
org.ghost4j.Ghostscript

public class Ghostscript extends Object
Class representing the Ghostscript interpreter.
  • Field Details

    • PROPERTY_NAME_ENCODING

      public static final String PROPERTY_NAME_ENCODING
      Name of the system property used to set the encoding to use for stdin.
      See Also:
    • nativeInstanceByRef

      private static GhostscriptLibrary.gs_main_instance.ByReference nativeInstanceByRef
      Holds Ghostscript interpreter native instance (C pointer).
    • instance

      private static Ghostscript instance
      Holds singleton instance.
    • stdIn

      private static InputStream stdIn
      Standard input stream.
    • stdOut

      private static OutputStream stdOut
      Standard output stream.
    • stdErr

      private static OutputStream stdErr
      Error output stream.
    • displayCallback

      private static DisplayCallback displayCallback
      Display callback used to handle display.
    • displayData

      private static DisplayData displayData
      Stores display data when working with display callback.
    • nativeDisplayCallback

      private static GhostscriptLibrary.display_callback_s nativeDisplayCallback
      Holds the native display callback.
  • Constructor Details

    • Ghostscript

      private Ghostscript()
      Private constructor.
  • Method Details

    • getInstance

      public static Ghostscript getInstance()
      Singleton access method.
      Returns:
      The singleton instance.
    • getDisplayCallback

      public DisplayCallback getDisplayCallback()
      Gets the display callback set on the Ghostscript interpreter (may be null if not set).
      Returns:
      The DisplayCallback or null
    • setDisplayCallback

      public void setDisplayCallback(DisplayCallback displayCallback)
      Sets a display callback for the Ghostscript interpreter.
      Parameters:
      displayCallback - DisplayCallback object
    • getStdErr

      public OutputStream getStdErr()
      Gets the error output stream of the Ghostscript interpreter (may be null if not set).
      Returns:
      The OutputStream or null
    • setStdErr

      public void setStdErr(OutputStream stdErr)
      Sets the error output stream of the Ghostscript interpreter.
      Parameters:
      stdErr - OutputStream object
    • getStdOut

      public OutputStream getStdOut()
      Gets the standard output stream of the Ghostscript interpreter (may be null if not set).
      Returns:
      The OutputStream or null
    • setStdOut

      public void setStdOut(OutputStream stdOut)
      Sets the standard output stream of the Ghostscript interpreter.
      Parameters:
      stdOut - OutputStream object
    • getStdIn

      public InputStream getStdIn()
      Gets the standard input stream of the Ghostscript interpreter (may be null if not set).
      Returns:
      The InputStream or null
    • setStdIn

      public void setStdIn(InputStream stdIn)
      Sets the standard input stream of the Ghostscript interpreter.
      Parameters:
      stdIn - InputStream object
    • getNativeInstanceByRef

      Singleton factory method for getting a Ghostscript,interpreter instance. Only called from class itself.
      Returns:
      Ghostscript instance.
      Throws:
      GhostscriptException
    • getDisplayData

      private DisplayData getDisplayData()
    • getRevision

      public static GhostscriptRevision getRevision()
      Gets Ghostscript revision data.
      Returns:
      Revision data.
    • initialize

      public void initialize(String[] args) throws GhostscriptException
      Initializes Ghostscript interpreter.
      Parameters:
      args - Interpreter parameters. Use the same as Ghostscript command line arguments.
      Throws:
      GhostscriptException
    • buildNativeDisplayCallback

      private GhostscriptLibrary.display_callback_s buildNativeDisplayCallback(DisplayCallback displayCallback) throws GhostscriptException
      Builds a native display callback from a DisplayCallback object.
      Parameters:
      displayCallback - DisplayCallback to use.
      Returns:
      The created native display callback.
      Throws:
      GhostscriptException
    • exit

      public void exit() throws GhostscriptException
      Exits Ghostscript interpreter. Must be called after initialize.
      Throws:
      GhostscriptException
    • runString

      public void runString(String string) throws GhostscriptException
      Sends command string to Ghostscript interpreter. Must be called after initialize method.
      Parameters:
      string - Command string
      Throws:
      GhostscriptException
    • runFile

      public void runFile(String fileName) throws GhostscriptException
      Sends file Ghostscript interpreter. Must be called after initialize method.
      Parameters:
      fileName - File name
      Throws:
      GhostscriptException
    • deleteInstance

      public static void deleteInstance() throws GhostscriptException
      Deletes the singleton instance of the Ghostscript object. This ensures that the native Ghostscrit interpreter instance is deleted. This method must be called if Ghostscript is not used anymore or maybe reinitialized.
      Throws:
      GhostscriptException