|Linux in a Nutshell
Amazon | Powells
Many people are familiar with the “print your own greeting card” idea. You print four small page images on a single sheet of paper and fold it in half twice. You get a little greeting card with a custom cover and interior, all from one single-sided piece of paper.
I wanted to do this from a Linux application, without needing Windows or MacOS. Preferably, I could use any application to produce 4 pages, and have some magic transform it into the single page with all parts reduced and oriented properly for folding.
After a little googling, I was able to find this list archive message by Ronan Heffernan describing exactly what I wanted. His “make_card” script takes a postscript file and does the appropriate transformation:
#!/bin/shcat $1 | pstops -pletter -b “4:3U@.5(1w,1h)+0U@.5(.5w,1h)+1@.5(0,0)+2@.5(.5w,0)” > $2
This works well, but I wanted something that my family could use from
Linux apps without the command line.
My favorite print spool tool in Linux is KPrinter from KDE 3.0. It can be used with any X Window application, not just KDE apps. It is perfect for the generic X apps like
Mozilla and Acrobat Reader. Instead of sending print output to the command lpr, send it to the command kprinter (or kprinter –stdin if it pipes it).
The method I found is to create a “prefilter” for KPrinter. This
allows you to select greeting card formatting for any print job to
Create the following files:
[KDE Print Filter Entry]Comment=Greeting card- 4 pages on double-folded US letterMimeTypeIn=application/postscriptMimeTypeOut=application/postscriptRequire=exec:/ps2ps
<!DOCTYPE kprintfilter><kprintfilter name=”Greeting-card-4-up” ><filtercommand data=”pstops -pletter -b ‘4:3U@.5(1w,1h)+0U@.5(.5w,1h)+1@.5(0,0)+2@.5(.5w,0)’ %filterinput %filteroutput” /> <filterinput><filterarg format=”%in” name=”file” /> <filterarg format=”” name=”pipe” /> </filterinput> <filteroutput><filterarg format=”> %out” name=”file” /> <filterarg format=”” name=”pipe” /></filteroutput></kprintfilter>
I found that the KDE prefilters were not terribly well documented, but I
was able to muddle through it. To create one, run KPrinter and select
“System Options”. In the print configuration dialog box, select “Commands”.
This will allow you to create a new filter. You simply need to compare the
entries to other existing print filters.
When your new filter is created, it will be in your personal directory, such as
Move it to your system-wide print filter directory, which might be
or something similar.
I could not get the paper size to work automatically using the poorly-documented
paper size substitution variable, so I had to hard-code the US Letter paper
size. If anyone knows how to fix this, let me know.
Submitted by amillar on Sat, 2004-02-07 13:35