[Tutor] Considering translating bash script to Python to learn
Dotan Cohen
dotancohen at gmail.com
Tue May 12 10:26:00 CEST 2009
I am considering translating a homegrown bash script to Python to
learn the language. The script grabs different specific pages of
either a ODF or PDF file (I can use either as the input file, based on
Python's abilities), combines it with an HTML file, rotates,
rearranges, then sends the whole thing to the printer. However, I seem
to depend on many bash-specific functions (os programs) and I cannot
find Python equivalents. Here are some lines of the script, and the
relevant questions:
gnome-web-print --mode=print --files $FILE /tmp/weeklyCalendar.pdf
Here, I am converting an HTML file to PDF. I rely on the external
program gnome-web-print to do the conversion. Does Python have a
native way to handle this, or would I just wind up calling
gnome-web-print from within python?
pdftops -f 2 -l 2 $HOME/.bin/todo/todo.odf.pdf /tmp/weeklyTodo.ps
Here I am exporting the second page of a PDF file as a PS file.
Actually, the file in question is a hybrid ODF-PDF file and if Python
has a way of exporting a specific page of a ODF file that is fine too.
I could export to PDF as well, the important bit is too isolate a
single page of either an ODF or PDF file and have it as either a PS or
PDF.
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite
-sOutputFile=/tmp/weeklyCalendarPrintMe.pdf
$HOME/.bin/todo/weeklyCalendar-blank.pdf /tmp/weeklyCalendar.pdf
/tmp/weeklyTodo.ps $HOME/.bin/todo/weeklyCalendar-blank.pdf
Here, I am combining several PDF and PS files as a single PDf file.
Can Python do this?
lpr -P printer -o number-up=2 /tmp/weeklyCalendarPrintMe.pdf
Here I am sending the final file to the printer, and having it print 2
pages on each page. Again, is this something that Python can handle
internally?
Thanks for the help. I know that Python is not specifically designed
to manipulate PDF files, but as the script is getting more complex and
performs logic in other sections (not shown here) I would like to take
advantage of other Python properties.
--
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
More information about the Tutor
mailing list