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
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Problem with PDF plugin on 2.8 ScooterBob 3 199 Apr 22, 2013 18:14
Last Post: rich2005
  [SOLVED] python plug-in, "RuntimeError ... gimp-file-load ... value out of range" Grafx 2 199 Mar 14, 2013 21:33
Last Post: ofnuts
  Batch process with blur on single layer in image uzzors2k 6 272 Dec 14, 2012 13:52
Last Post: uzzors2k
  Batch process - adding a text layer. eppc 4 509 Nov 13, 2012 12:43
Last Post: eppc
  watermark-batch adrien 5 420 Oct 28, 2012 17:54
Last Post: rich2005

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS