Gimp-Forum.net

Full Version: How to batch open multiple PDF files and batch export them again as PDF files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I've been reading a bit about the gimp batch mode and gimp scripts but I'm not sure what I'm trying to do is possible and I was looking for some guidance.

I have multiple PDF files (let's say 100). I want to batch open them with GIMP (specifying the resolution - DPI) and maybe even more options (Anti-aliasing, the layer etc). Then I want to directly export them as PDF again (specifying the export options - apply layer masks, convert bitmaps and omit hidden layers).

Is this possible in the first place? And if yes, could you please give me some pointers as to how I can achieve that?

Thank you very much in advance!
You can't specify the resolution when importing them via the API, unfortunately.
Saw your post on gimpchat, are you an ex-M$ photoshop user? If so then try and forget old PS habits. Using Gimp 2.8, nothing wrong with that, old plugins more likely to work. Probably not using a cutting edge linux, again nothing wrong with that. (oh, just seen you are from CERN - very impressive)

Apart from a bespoke plugin and Ofnuts gave advice on that. My thoughts on the subject.

100 PDF's to open. Gimp can open as layers but that involves 100 clicks on the import button. Take into consideration that Gimp will render the PDF(s) to bitmaps. What was a scalable vector (including text) becomes a fixed ppi bitmap. If the PDF's are multi-page, Gimp will number the layers per document ie. 1,2,3, 1#1,2#1,3#1,4 which can result in a scrambled final combined PDF. There are scripts/plug-ins that will rename layers with consecutive numbers.

A better way is combine the pdfs beforehand with a utility such as PDFsam (pdf split-and-merge) there is a free version. Combining will give a single PDF to open in Gimp.
or
If many of pages are pure text, splitting allows picking just the graphic pages from the PDF(s) to be edited/recombined. Depending on the number of pure text pages this can make a big difference in the final PDF size.

edit: Also have a look at pdftk. It is command line but more suitable for a linux bash file.

What is possible with Gimp (and linux)
Install ImageMagick (IM), it is probably already there, if not it will be in your disto repository.
Export all the layers, there are scripts/plugins for this, the attached sg-save-all-layers.scm exports as png, will flatten layer groups and layer masks (not all will do that) screenshot: https://i.imgur.com/k0HgM6q.jpg  Now combine those into a PDF using IM convert command

Code:
convert /path/to/*.png new.pdf

(note about IM and pdf/eps/ps formats. I use Kubuntu 16.04 that command suddenly stopped working with the last update, a month ago. Had to go into /etc/ImageMagick-6/policy.xml and comment out those disabled formats. Why disabled? Who knows.)

ImageMagick same as Gimp, rasterizes any file so you do end up with large PDF's

The above but straight from Gimp.
There is a (old, bit flakey) plug-in export-layers-to-pdf.py (attached) that uses IM (see note about pdf format) to export the layers to a temp folder, combines those to a new PDF. Caveats, will fail with layer groups and layer mask so up-to-you to flatten first. screenshot with result open in PDF viewer: https://i.imgur.com/CqG5eMg.jpg Choose a quality setting less than 100 and the bitmaps are jpeg, makes a big difference to the PDF size.

Long and complicated: Yes, but at least it is not dumbed-down click-n-wish.