Python + nconvert
Posted: Thu Apr 09, 2009 9:17 pm
I downloaded nconvert from two days, my first look to "help" gave me the neat feel that it has been written in old chinese, but at a fourth-fifth look I understood something. I know by experience that this is pretty common dealing with a new application.
My goal was, to control into any possiblie detail the conversion pdf -> jpeg that have to be processed with Djvu Solo into djvu files. This procedure is what's needed to publish into http://commons.wikimedia.org a good, compressed file collecting the images of Public Domain books, as a documented source for careful, cooperative transciption into one of many existing Wikisource projects, the "PD library" branch of wiki project.
After some tests from command prompt and from a bat file, I used for the first time the os.system() function of python, that sends a string to OS just like command prompt does.
My first running, and useful, python script is the following:
>>> import os
>>> for i in range(2,6):
os.system("nconvert -out jpeg -o vipere#.jpg -page # -q 95 -dpi 300 -autocrop 20 255 255 255 vipere.pdf".replace("#",str(i)))
that is the same I'd get with four commands from command prompt:
c:> nconvert -out jpeg -o vipere1.jpg -page 1 -q 95 -dpi 300 -autocrop 20 255 255 255 vipere.pdf
c:> nconvert -out jpeg -o vipere2.jpg -page 2 -q 95 -dpi 300 -autocrop 20 255 255 255 vipere.pdf
..... and so on (the python script simply replaces # with 2,3,4,5 while cycling).
Well... IT RUNS!
Thanks to XnView and Nconvert creators!

My goal was, to control into any possiblie detail the conversion pdf -> jpeg that have to be processed with Djvu Solo into djvu files. This procedure is what's needed to publish into http://commons.wikimedia.org a good, compressed file collecting the images of Public Domain books, as a documented source for careful, cooperative transciption into one of many existing Wikisource projects, the "PD library" branch of wiki project.
After some tests from command prompt and from a bat file, I used for the first time the os.system() function of python, that sends a string to OS just like command prompt does.
My first running, and useful, python script is the following:
>>> import os
>>> for i in range(2,6):
os.system("nconvert -out jpeg -o vipere#.jpg -page # -q 95 -dpi 300 -autocrop 20 255 255 255 vipere.pdf".replace("#",str(i)))
that is the same I'd get with four commands from command prompt:
c:> nconvert -out jpeg -o vipere1.jpg -page 1 -q 95 -dpi 300 -autocrop 20 255 255 255 vipere.pdf
c:> nconvert -out jpeg -o vipere2.jpg -page 2 -q 95 -dpi 300 -autocrop 20 255 255 255 vipere.pdf
..... and so on (the python script simply replaces # with 2,3,4,5 while cycling).
Well... IT RUNS!

Thanks to XnView and Nconvert creators!