Class GhostscriptHelper
A utility class that is used as an interface to run 3rd-party tool Ghostscript.
public class GhostscriptHelper
- Inheritance
-
GhostscriptHelper
- Inherited Members
Remarks
A utility class that is used as an interface to run 3rd-party tool Ghostscript. Ghostscript is an interpreter for the PostScript language and PDF files, it allows to render them as images.
The Ghostscript needs to be installed independently on the system. This class provides a convenient way to run it by passing a terminal command. The command can either be specified explicitly or by a mean of environment variable GHOSTSCRIPT_ENVIRONMENT_VARIABLE.Constructors
GhostscriptHelper()
Creates new instance that will rely on Ghostscript execution command defined by GHOSTSCRIPT_ENVIRONMENT_VARIABLE environment variable.
public GhostscriptHelper()
GhostscriptHelper(string)
Creates new instance that will rely on Ghostscript execution command defined as passed argument.
public GhostscriptHelper(string newGsExec)
Parameters
newGsExec
stringthe Ghostscript execution command; if null - environment variables will be used instead
Fields
GHOSTSCRIPT_ENVIRONMENT_VARIABLE
The name of the environment variable with the command to execute Ghostscript operations.
public const string GHOSTSCRIPT_ENVIRONMENT_VARIABLE = "ITEXT_GS_EXEC"
Field Value
Methods
GetCliExecutionCommand()
Returns a command that is used to run the utility.
public virtual string GetCliExecutionCommand()
Returns
- string
a string command
Remarks
Returns a command that is used to run the utility. This command doesn't contain command parameters. Parameters are added on specific methods invocation.
RunGhostScriptImageGeneration(string, string, string)
Runs Ghostscript to render the PDF's pages as PNG images.
public virtual void RunGhostScriptImageGeneration(string pdf, string outDir, string image)
Parameters
pdf
stringPath to the PDF file to be rendered
outDir
stringPath to the output directory, in which the rendered pages will be stored
image
stringString which defines the name of the resultant images. This string will be concatenated with the number of the rendered page from the start of the PDF in "-%03d" format, e.g. "-011" for the eleventh rendered page and so on. This number may not correspond to the actual page number: for example, if the passed pageList equals to "5,3", then images with postfixes "-001.png" and "-002.png" will be created: the former for the third page, the latter for the fifth page. "%" sign in the passed name is prohibited.
Remarks
Runs Ghostscript to render the PDF's pages as PNG images.
Note, that this method may create temporary directory and files.RunGhostScriptImageGeneration(string, string, string, string)
Runs Ghostscript to render the PDF's pages as PNG images.
public virtual void RunGhostScriptImageGeneration(string pdf, string outDir, string image, string pageList)
Parameters
pdf
stringPath to the PDF file to be rendered
outDir
stringPath to the output directory, in which the rendered pages will be stored
image
stringString which defines the name of the resultant images. This string will be concatenated with the number of the rendered page from the start of the PDF in "-%03d" format, e.g. "-011" for the eleventh rendered page and so on. This number may not correspond to the actual page number: for example, if the passed pageList equals to "5,3", then images with postfixes "-001.png" and "-002.png" will be created: the former for the third page, the latter for the fifth page. "%" sign in the passed name is prohibited.
pageList
stringString with numbers of the required pages to be rendered as images. This string should be formatted as a string with numbers, separated by commas, without whitespaces. Can be null, if it is required to render all the PDF's pages.
Remarks
Runs Ghostscript to render the PDF's pages as PNG images.
Note, that this method may create temporary directory and files.