PDF to JPEG with ImageMagick and Ghostscript

Post Reply
mkis
Member
Posts: 20
Joined: Fri Oct 21, 2011 3:19 pm
Location: Ahaus, Germany
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by mkis »

Hello all,



I've got a problem with converting PDF to JPG with ImageMagick (and Ghostscript)

There is a flow with the "execute command". The program that is used is convert from ImageMagick, simply using the "%1" "%2" arguments.

output File Extension is jpg.



Now every PNG, TIF or any other image is running perfect through this flow.

But any PDF File is send to null by switch...

Using an Switch Script is also NOT working!



The same command manual used in the terminal is working!



Does anyone have a solution for that?

Or have an alternative tool (exept Acrobat or SIPS) to get good quality jpgs from PDFs?



Thanks in advance!



Michael
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by dkelly »

Hello, if you are using "Execute command" configurator then you should be able to select one of the Output properties that supports "Copy input job" == yes option.
mkis
Member
Posts: 20
Joined: Fri Oct 21, 2011 3:19 pm
Location: Ahaus, Germany
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by mkis »

Hello Dwight,



thanks for your answer, I've tried any possible options in the "Execute command" and always the same error.

Job send to null...



With a similar SwitchScript in JavaScript an error occures, the gs command can't find the file to convert.



But from the terminal with the same arguments the converting works fine.



Regards,



Michael
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by dkelly »

I know it will work with a JS script because I've done it many times. You have to create a job folder, move the PDF and JPEG file into it and then call SendToSingle() with the job folder.
mkis
Member
Posts: 20
Joined: Fri Oct 21, 2011 3:19 pm
Location: Ahaus, Germany
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by mkis »

OK, then I think I'll check the ImageMagick Installation first.

Maybe there is something broken....



Thanks for your help!



Michael
mkis
Member
Posts: 20
Joined: Fri Oct 21, 2011 3:19 pm
Location: Ahaus, Germany
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by mkis »

Hello again.



I'm sorry, but I didn't get it.

In my script, the ImageMagick wont't work, I always get an error "gs: can't find the image..."



So Ghostscript won't get thr image from ImageMagick, because switch already runs in an error?



So here's my script, maybe someone can help...



Thanks!!!!





function jobArrived( s : Switch, job : Job )

{

var theProcessPath = s.getPropertyValue( "argProcessPath" );

var thePixelWidth = s.getPropertyValue( "argPixelWidth" );

var theOutputFormat = s.getPropertyValue( "argOutputFormat" );

var theArguments = new Array();

// var theTempPath = job.createPathWithName( job.getNameProper() );

var theOutputFile = "/path_without_spaces" + job.getNameProper() + "." + theOutputFormat;



theArguments.push( theProcessPath );

theArguments.push( job.getPath() );

theArguments.push( theOutputFile );

theArgumentsString = theArguments.join(" ");



var returnCode = Process.execute( theArgumentsString );



job.log (2, theArgumentsString );



if( Process.stderr != "" ) {

job.log( 3, "Prozess-Fehler: " + Process.stderr );

}



if( new File( theOutputFile ).exists ) {

job.sendToSingle( theOutputFile );

job.sendToSingle( job.getPath() );

} else {

job.log(3, "IM-Datei existiert nicht!: " + Process.stderr );

}

}
roope
Newbie
Posts: 1
Joined: Wed Jul 20, 2011 2:47 pm

PDF to JPEG with ImageMagick and Ghostscript

Post by roope »

Hi Michael,



Can you still try execute command with GhostScript? Here is sample settings which are working for me.



Command or Path: C:Program Filesgsgs9.06bingswin32c.exe



Arguments: -dSAFER -dBATCH -dNOPAUSE -r300 -dJPEGQ=80 -dDOINTERPOLATE -dMaxBitmap=500000000 -dUseTrimBox -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sDEVICE=jpeg -o "%2" "%1"



Output: File at path



Copy input job: No



Output extension: JPEG (*.jpg; *.jpeg)



Fail if exit code is: Nonzero



Have you done some conversions with ImageMagic from png or tiff to jpg? Can you give some sample settings?



-Robert
mkis
Member
Posts: 20
Joined: Fri Oct 21, 2011 3:19 pm
Location: Ahaus, Germany
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by mkis »

Hi Robert,



thanks for your answer, this gives me a temporary solution for my problem.

I'll use your direkt command for PDF Files now, thanks!



With ImageMagick I'm using

Arguments: "%1" -compress JPEG -quality 99 "%2"

The rest as for Ghostscript...



Regards,

Michael
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

PDF to JPEG with ImageMagick and Ghostscript

Post by dkelly »

Hello, just use the arguments array directly instead of combining them into a string.



mkis wrote: var theArguments = new Array();

var theOutputFile = "/path_without_spaces" + job.getNameProper() + "." + theOutputFormat;



theArguments.push( theProcessPath );

theArguments.push( job.getPath() );

theArguments.push( theOutputFile );

var returnCode = Process.execute( theArguments );





}
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: PDF to JPEG with ImageMagick and Ghostscript

Post by freddyp »

As I was searching for something else I stumbled over this very old post and I saw that it does not have a conclusive answer and I thought I would add it now as it is still relevant today and possibly for other applications than Imagemagick too.

When running "Execute command" the application is not run in the same environment as when you are running it in Terminal/Command prompt so you cannot rely on all environment variables (esp. PATH) to be the same, even to be defined. And that is where the problem lies with Imagemagick/Ghostscript. Imagemagick calls Ghostscript by simply calling "gs" or "gsc" and when the PATH variable does not include the location of Ghostscript it will fail.

Solution: do not run Imagemagick directly in "Execute command", but run a shell script/BAT file so you can set the PATH variable correctly before running Imagemagick.
nehavilash
Newbie
Posts: 7
Joined: Mon Nov 04, 2024 11:14 am
Location: India
Contact:

Re: PDF to JPEG with ImageMagick and Ghostscript

Post by nehavilash »

You can try setting the PATH variable for Ghostscript in a shell script before running ImageMagick. This should fix the issue where Ghostscript isn't found. Also, for quick JPEG compression, you can use online jpeg compressor tool to compress your images without losing quality.
Post Reply