Post Reply 

Batch conversion of PDF file ?

Dec 29, 2011, 11:30
Post: #1
Batch conversion of PDF file ?
I'm trying to develop a script-fu that would import a PDF file in non interactive mode and generate jpg images for each page. Problem is I couldn't find any example of how to script the PDF import function in batch mode.

Can somebody point me at some sample code or give me a hint on how do that ?

Thanks a lot for you help.

Eljay
Find all posts by this user
Quote this message in a reply
Dec 30, 2011, 00:20
Post: #2
RE: Batch conversion of PDF file ?
Why don't you use ImageMagick "convert" for that? As simple as:
Code:
convert input.pdf output.jpg

(although IMHO the PNG format is more suitable for output, the file will be likely smaller and without compression artifacts)(see http://gimpforums.com/thread-pros-and-co...ge-formats)

AFAIK Gimp and ImageMagick both rely on Ghostscript to do the real conversion, so if Gimp can do it so will ImageMagick.

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Dec 30, 2011, 12:38
Post: #3
RE: Batch conversion of PDF file ?
@eljay
When I saw your post, first thought was Imagemagick, but then howto implement in script-fu, Don't know.

The basic IM comand is trivial

convert filename.pdf[n] filename.ext

where n is a page number starting at 0 (= page no.1)

I would use a bash file to loop through the pages as I don't do any script-fu or python.

A quick search, nothing on script-fu but maybe be possible in python.

Here is a plugin that calls IM from gimp - long shot but maybe a starting point.

http://www.mm-log.com/blog/2010-01-21/us...ithin-gimp
Find all posts by this user
Quote this message in a reply
Dec 30, 2011, 14:18
Post: #4
RE: Batch conversion of PDF file ?
Thanks for your suggestion of using IM to do the job. This is actually what we use right now. However we noticed that in many cases Gimp does a much better job at converting PDF files to Jpeg than IM does. We tried hard to fine tune the various options of the IM convert tool but rarely achieved as good results as Gimp.

Hence my question and the idea of scripting Gimp
Find all posts by this user
Quote this message in a reply
Dec 30, 2011, 16:54 (This post was last modified: Dec 30, 2011 16:58 by ofnuts.)
Post: #5
RE: Batch conversion of PDF file ?
Gimp (or IM) will not give you anything better than what GhostScript produces directly since in this case they are only the middle men. On a PDF I have, this:
Code:
ghostscript -dSAFER -dBATCH -dNOPAUSE -r300 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sDEVICE=png16m "-sOutputFile=OPA%02d.png" OPA2134-Datasheet.pdf
Produced this:

   

The important parameters above are:
  • -sDEVICE=png16m: the output format (PNG here, you can't worry about quality and use JPG, but thare are also JPG devices if needed Smile )
  • -r300: the DPI resolution (you can also set an output size in pixels)
  • -dGraphicsAlphaBits=4 -dTextAlphaBits=4: Sets anti-aliasing for text and graphics to the maximum
  • -sOutputFile=OPA%02d.png: set the output file names for individual pages to OPA01.png, OPA02.png...
This produces 14 pages in 14 seconds on my Core I5 laptop.

As much as I love Gimp and writing scripts for it, I think its batch mode is barely usable and unless you are using very specific filters or operations, it should be avoided at all costs (and given the options in IM, it is rather easy to avoid).

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Dec 30, 2011, 20:57
Post: #6
RE: Batch conversion of PDF file ?
Ah nice !
I kew ghostscript was used both by IM and Gimp but didn't known which ghostscript command line to use. I'm going to try this one right away. Thank you !
Find all posts by this user
Quote this message in a reply
Dec 30, 2011, 21:20
Post: #7
RE: Batch conversion of PDF file ?
More at: http://ghostscript.com/doc/current/Readme.htm

[Image: 2Tvo0.png]

Visit this user's website Find all posts by this user
Quote this message in a reply
Oct 21, 2013, 10:20
Post: #8
RE: Batch conversion of PDF file ?
(Dec 30, 2011 16:54)ofnuts Wrote:  Gimp (or IM) will not give you anything better than what GhostScript produces directly since in this case they are only the middle men. On a PDF I have, this:
Code:
ghostscript -dSAFER -dBATCH -dNOPAUSE -r300 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sDEVICE=png16m "-sOutputFile=OPA%02d.png" OPA2134-Datasheet.pdf

Just to add a note for anyone trying this on Windows - the % needs to be escaped as %% in any batch files (otherwise it will interpret OPA%02d.png as "OPAC:\batchfile.bat.png")
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Bashing my head - Batch Python Script nmiltner 3 187 Sep 5, 2014 07:03
Last Post: ofnuts
Question Load PDF and load images Vash Stampida 4 271 Aug 7, 2014 20:05
Last Post: Vash Stampida
  Batch processing script Help jarboe3142 3 340 Jun 1, 2014 21:53
Last Post: paynekj
  CMYK Conversion crzycowboy 13 4,494 Apr 10, 2014 11:27
Last Post: rich2005
  GIMP batch process script run-time error Paddy Landau 4 727 Apr 8, 2014 22:42
Last Post: ofnuts

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS