You are here

Export Layers as PDF

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!

I'm tired of building a PDF from layers manually so I finally got around to scripting it. This requires "convert" from ImageMagick to be installed. It has been tested on Linux(Ubuntu).

Code License: 
GIMP Version: 
Scripting Engine: 

Comments

I found this script for making PDF files with searchable OCR over at http://blog.konradvoelkel.de/2010/01/linux-ocr-and-pdf-problem-solved. It would be awesome to somehow have this integrated into this plugin!


#!/bin/bash
echo "usage: pdfocr.sh document.pdf orientation split left top right bottom lang author title"
# where orientation is one of 0,1,2,3, meaning the amount of rotation by 90°
# and split is either 0 (already single-paged) or 1 (2 book-pages per pdf-page)
# and (left top right bottom) are the coordinates to crop (after rotation!)
# and lang is a language as in "cuneiform -l".
# and author,title are used for the PDF metadata
# all values relative to a resolution of 300dpi
#
# usage examples:
# ./pdfocr.sh SomeFile.pdf 0 0 0 0 2500 2000 ger SomeAuthor SomeTitle
# will process a PDF with one page per pdf-page, cropping to width 2500 and height 2000
pdftk "$1" burst dont_ask
for f in pg_*.pdf
do
echo "pre-processing $f ..."
convert -quiet -rotate $[90*$2] -monochrome -normalize -density 300 "$f" "$f.png"
convert -quiet -crop $6x$7+$4+$5 "$f.png" "$f.png"
if [ "1" = "$3" ];
then
convert -quiet -crop $[$6/2]x$7+0+0 "$f.png" "$f.1.png"
convert -quiet -crop 0x$7+$[$6/2]+0 "$f.png" "$f.2.png"
rm -f "$f.png"
else
echo no splitting
fi
rm -f "$f"
done
for f in pg_*.png
do
echo "processing $f ..."
convert "$f" "$f.bmp"
cuneiform -l $8 -f hocr -o "$f.hocr" "$f.bmp"
convert -blur 0.4 "$f" "$f.bmp"
hocr2pdf -i "$f.bmp" -s -o "$f.pdf" < "$f.hocr" rm -f "$f" "$f.bmp" "$f.hocr" done echo "InfoKey: Author" > in.info
echo "InfoValue: $9" >> in.info
echo "InfoKey: Title" >> in.info
echo "InfoValue: $10" >> in.info
echo "InfoKey: Creator" >> in.info
echo "InfoValue: PDF OCR scan script" >> in.info
pdfjoin --fitpaper --tidy --outfile "$1.ocr1.pdf" "pg_*.png.pdf"
rm -f pg_*.png.pdf
pdftk "$1.ocr1.pdf" update_info doc_data.txt output "$1.ocr2.pdf"
pdftk "$1.ocr2.pdf" update_info in.info output "$1-ocr.pdf"
rm -f "$1.ocr1.pdf" "$1.ocr2.pdf" doc_data.txt in.info
rm -rf pg_*_files

I have wrote new version. Where I can upload it?
No answers?

OK,
I have created new thread with new plugin "Export Layers to single multiple pages PDF"

On GIMP 2.6.11 on Mac OS X Mountain Lion, I get this error (and additionally, the dialog seems odd in that it forces me to pick a file name from a file browser, when what I wish to do is save the file as a new file):

Traceback (most recent call last):
File "/tmp/skl/Gimp.app/Contents/Resources/lib/gimp/2.0/python/gimpfu.py", line 692, in response
dialog.res = run_script(params)
File "/tmp/skl/Gimp.app/Contents/Resources/lib/gimp/2.0/python/gimpfu.py", line 353, in run_script
return apply(function, params)
File "/tmp/skl/Gimp.app/Contents/Resources/lib/gimp/2.0/plug-ins/export_layers_pdf-0.2.py", line 52, in export_layers
combine_imgs_into_pdf(imgfiles, pdfname)
File "/tmp/skl/Gimp.app/Contents/Resources/lib/gimp/2.0/plug-ins/export_layers_pdf-0.2.py", line 32, in combine_imgs_into_pdf
check_call(['convert'] + imgfiles + [pdfname])
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 457, in check_call
retcode = call(*popenargs, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 444, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 594, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 1097, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

I put this script in the ~/.gimp-2.6/scripts folder and restarted gimp but there were no scripts listed (in either the python-fu or script-fu consoles) by any names I could think of such as "export_layers_pdf" or "python-fu-export-pdf" etc...

I also tried placing this script in the ~/.gimp-2.6/plug-ins folder but still no luck at locating the script or any menu item for it from within gimp.

Has any one been able to figure out how to run this script from within gimp? If so, did it work and how did you get it to show up inside gimp so that you could run it?

If Linux, you need to give the py file permission to execute.

Did it still have the .txt extension when you uploaded it to the plug-ins folder?

Shows under File - Export Layers - As PDF

There is a reason to use ImageMagick instead then Ghostscript ?

WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\docume~1\\compaq~1.fam\\locals~1\\temp\\tmpzaxus7.tiff'

Trace back

Traceback (most recent call last):
File "C:\Program Files\GIMP-2.0\lib\gimp\2.0\python\gimpfu.py", line 692, in response
dialog.res = run_script(params)
File "C:\Program Files\GIMP-2.0\lib\gimp\2.0\python\gimpfu.py", line 353, in run_script
return apply(function, params)
File "C:\Documents and Settings\Compaq_Owner.FAMILY-ROOM\.gimp-2.6\plug-ins\export_layers_pdf-0.1.py", line 55, in export_layers
os.remove(img)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\docume~1\\compaq~1.fam\\locals~1\\temp\\tmpuna0eg.tiff'

I noticed the file is associated with XnView.I tried to re-associate it with Imagemagick but got another error.

Subscribe to Comments for "Export Layers as PDF"