public class GhostscriptHelper extends Object
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
GhostscriptHelper.GhostscriptExecutionException
Exceptions thrown when errors occur during generation and comparison of images obtained on the basis of pdf
files.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
GHOSTSCRIPT_ENVIRONMENT_VARIABLE
The name of the environment variable with the command to execute Ghostscript operations.
|
| Constructor and Description |
|---|
GhostscriptHelper()
Creates new instance that will rely on Ghostscript execution command defined by
GHOSTSCRIPT_ENVIRONMENT_VARIABLE environment variable. |
GhostscriptHelper(String newGsExec)
Creates new instance that will rely on Ghostscript execution command defined as passed argument.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getCliExecutionCommand()
Returns a command that is used to run the utility.
|
void |
runGhostScriptImageGeneration(String pdf,
String outDir,
String image)
Runs Ghostscript to render the PDF's pages as PNG images.
|
void |
runGhostScriptImageGeneration(String pdf,
String outDir,
String image,
String pageList)
Runs Ghostscript to render the PDF's pages as PNG images.
|
public static final String GHOSTSCRIPT_ENVIRONMENT_VARIABLE
public GhostscriptHelper()
GHOSTSCRIPT_ENVIRONMENT_VARIABLE environment variable.public GhostscriptHelper(String newGsExec)
newGsExec - the Ghostscript execution command; if null - environment variables will be used insteadpublic String getCliExecutionCommand()
public void runGhostScriptImageGeneration(String pdf, String outDir, String image) throws IOException, InterruptedException
Note, that this method may create temporary directory and files.
pdf - Path to the PDF file to be renderedoutDir - Path to the output directory, in which the rendered pages will be storedimage - String 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.IOException - if there are file's reading/writing issuesInterruptedException - if there is thread interruption while executing GhostScript.public void runGhostScriptImageGeneration(String pdf, String outDir, String image, String pageList) throws IOException, InterruptedException
Note, that this method may create temporary directory and files.
pdf - Path to the PDF file to be renderedoutDir - Path to the output directory, in which the rendered pages will be storedimage - String 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 - String 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.IOException - if there are file's reading/writing issuesInterruptedException - if there is thread interruption while executing GhostScript.Copyright © 1998–2024 Apryse Group NV. All rights reserved.