Ralph wrote on 01/24/2006 12:19:13 PM:
> in my WO application, I use ImageMagick's "identify" command line
> tool to get various properties of image files.
>
> However, in order to get the properties of EPS files, ImageMagick's
> "identify" uses ghostscript (calls gs), which I have downloaded and
> installed separately.
>
> "identify" also works nicely and seemlessly with the command line on
> EPS files exactly the same way it would work with JPEGs etc.
We use imagemagick + ghostscript to convert some pdfs into tiffs. I didn't write this code, but I remember the developer working through it and figuring out everything necessary to get it to work. We had to go through some additional hoops to get ghostscript to recognize a certain version of a font we needed, but this code lets us use imagemagick+ghostscript on both Windows and Solaris (I may have snipped a few bits to hide certain non-public data):
String tmpdir = NSProperties.getProperty("tmpdir");
String command = NSProperties.getProperty("convertPath"); // path to convert executable
String execPath = NSProperties.getProperty("runtimeExecPath");
String platform = System.getProperty("os.name");
log.info("I'm running on: "+platform);
String[] vars = new String[5];
if(platform.indexOf("Win") != -1)
{
vars[0] ="";
vars[1] ="";
vars[2] ="";
vars[3] ="";
vars[4] ="";
}
else
{
vars[0] = "PATH=$PATH:"+NSProperties.getProperty("runtimeExecPath");
vars[1] = "LD_LIBRARY_PATH="+NSProperties.getProperty("ld_library_path");
vars[2] = "MAGICK_HOME="+NSProperties.getProperty("magick_home");
vars[3] = "GS_FONTPATH="+NSProperties.getProperty("gs_fontpath");
vars[4] = "GS_LIB="+NSProperties.getProperty("gs_lib");
}
File f = new File(tmpdir+filename);
FileOutputStream fout = new FileOutputStream(f);
JasperExportManager.exportReportToPdfStream(jasperPrint, fout);
fout.flush();
fout.close();
//convert -density 144 PDF:test.pdf -monochrome -compress Fax TIFF:test.tiff
String[] commands = new String[8];
commands[0] = command;
commands[1] = "-density";
commands[2] = "200";
commands[3] = tmpdir+filename;
commands[4] = "-monochrome";
commands[5] = "-compress";
commands[6] = "Fax";
commands[7] = tmpdir+filename.replaceAll(".pdf", ".tiff");
//ok, we wrote the pdf.. now see if we can convert it to tiff...
log.info("Starting the pdf->tiff conversion:");
log.info("Command: ");
for(int i=0; i<commands.length; i++)
{
log.info(commands[i]);
}
log.info("Environment:");
for(int i=0; i<vars.length; i++)
{
log.info(vars[i]);
}
Process p = Runtime.getRuntime().exec(commands, vars);
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
p.waitFor();
while (b.ready())
{
log.info(b.readLine());
}
while (err.ready())
{
log.error(err.readLine());
}
int retVal = p.exitValue();
log.info("pdf converter retval = " + retVal);
Hope it helps.
Logan
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]
