Reputation: 1196
String[] cmd = {
"gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile= C:\\Users\\342008\\Desktop\\t\\Pa_10_12.pdf C:\\Users\\342008\\Desktop\\t\\P1_10_12.pdf"
};
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {}
am trying to use ghost script to reduce the PDF file size with the help of command line argumenet, am getting IOexception for the above input string object cmd, could some one please help run this command to use ghostscript?
Upvotes: 0
Views: 1338
Reputation: 31199
Firstly, while it is possible that running a PDF file through the pdfwrite device will make the file smaller, this is not the purpose of the device, and there are circumstances under which it will produce a bigger file.
If you really want to do this, then don't use the -dPDFSETTINGS switch. Instead set each parameter individually, take the time to read the documentation and see what they do so that you can make an informed choice.
You haven't said what operating system you are using, nor which version of Ghostscript, but I can see several possible problems:
1) The Ghostscript executable is not called 'gs' on all operating systems, possibly you are using the wrong name. The syntax of the parameters leads me to believe this is a Windows system, in which case the executable is called gswin32 (for the windowed version) or gswin32c (for the command line version).
2) You haven't specified a path to the executable. This will only work if the executable can be found on the OS' search path (usually the %PATH% environment variable)
Your command line apparently includes "-sOutputFile= C:\Users\342008\Desktop\t\Pa_10_12.pdf" You must NOT leave extraneous spaces in parameters. What you have written there will cause GS to assume an output file with an empty name, and then treat the filename as an input file for processing.
I would suggest that before you try this in Java you try running the command from the command line of your Operating System. If that doesn't work then it isn't going to work from Java either......
Upvotes: 3