Herbert Georg wrote:
Is there any way to produce a booklet from a PDF file without having
to buy adobe acrobat?
./pipe_printer_tofile.sh
foo
bar
^D (to quit)
cat /tmp/pipe_print/pipe_printer_data.ps
foo
bar
========================
I changed the subject line because I wasn't sure if I was answering the
question you had, but I thought I'd post my tips and tricks anyway :)
I've had some fun trying to get N-up printing working nicely with
several apps through CUPS, specifically Acrobat and OpenOffice, but
eventually I found a generic mechanism that works for pretty well anything.
There are a few problems I found:
- CUPS N-Up printing, or specifically 4-up printing selected from the
printer dialog, doesn't let you chose the layout of the page. It's
always topleft, topright, bottomleft, bottomright.
- You can add filters to a CUPS printer to do decent N-Up printing, and
booklet printing, and many other things, but some apps (specifically
OpenOffice) manage to somehow ignore these settings.
- Acrobat 7 also had print problems, I never really worked out what was
going on but printing directly from Acrobat produced blank output.
- Generally I want the kprinter dialog to run for *all* applications,
even ones with no printer configuration.
My eventual solution has three components:
(A) 4-up printing via psnup
I set up special instances of my default printer queue for 2-up and 4-up
printing. To do this, go to the KDE Printing Manager
(menu:Utilities/Printing/Printing Manager), select a working printer, go
to the "Instances" tab, and click "Copy".
To use psnup to do 4-up printing, go to the "Settings" dialog for a
particular instance, ignore the "pages-per-sheet" setting, instead find
the "Filters" tab. It may be tricky to find, it's the far-right tab and
you may need to scroll the tabs to find it.
Click the "Add filter" button - it looks like a funnel.
Choose "Multiple Pages per Sheet Filter" - don't click "OK straight away
though....
Behind the scenes, this calls "psnup". "man psnup" indicates that for
my personal printing preferences I want to actually call "psnup -c".
So click the spanner next to the command (the tooltip is "Edit
Command"), and then click the "Edit Command" button on the "Command edit
for psnup" dialog.
The command will be something like "psnup -p%psl %filterargs
%filterinput %filteroutput" - change this to "psnup -c -p%psl
%filterargs %filterinput %filteroutput"
Click "Ok" multiple times until you get back to the filter dialog.
Click "Configure Filter" (the spanner icon) and set the pages-per-sheet
parameter to the pages per sheet you want for this printer, then click "Ok".
Click "Save" to save the filter settings for this printer
You now have a printer instance that always prints N-Up.
Note that the same mechanism can be extended for any number of different
filter combinations. There is a "booklet" printing filter there, which
is probably related to the original poster's requirements...
You can now print to this printer instance from any well-behaved
cups-based program, or from any program that lets you specify "kprinter"
as the print command.
However, Open Office at least is *not* well behaved - it runs it's own
Cups-based printer dialog, and if you want to do something outside the
norm, you are screwed. Standard advice on the net is to disable CUPS
printing entirely from Open Office, which is a bit of overkill IMHO.
Instead, I managed to set up a virtual printer, which basically allows
you to print to a valid CUPS printer which actually just writes
postscript data to a file, and then run another command to print that file.
(Note: I'm sure there are smoother ways to set this up, and indeed to do
it all as a single command using named pipes or something - but I wanted
a clean solution as soon as possible, and this one works for me :)
(B) Creating a virtual cups printer
First run Yast, go to Hardware/Printer, and select "Other" and click
"Configure" to add a new printer.
On "Select your printer type" choose "Other kind of setup"
On the next "Select your printer type" choose "Pipe Printing"
On the "Printing to Pipe" command page, you need a program to run. So
open another terminal window, and do the following:
- choose a directory where you put useful scripts and the like
- create a script - mine is called "pipe_printer_to_file.sh" - with
content like the following: (you don't need the logger commands, but
they can help diagnosis)
========================
#!/bin/bash
logger pipe_printer:creating
cat - > /tmp/pipe_print/pipe_printer_data.ps
chmod a+rw /tmp/pipe_print/pipe_printer_data.ps
logger pipe_printer:done.
========================
- chmod "pipe_printer_to_file.sh" so the 'lp' user is allowed to find
and run it. (this may include setting global read and execute
permissions on the file and the directory it lives in - I can't remember
what I set here)
- create a directory for the piped printer data (/tmp/pipe_print above)
as root:
========================
# mkdir /tmp/pipe_print
# chown lp:lp /tmp/pipe_print
# chmod a+r /tmp/pipe_print
========================
(Note that the "pipe_printer_to_file.sh" gets run as lp, but you want to
be able to read the produced postscript file as your logged in user,
hence all this permissions fiddling)
Now you have a script that should take standard input, and save it to
the file /tmp/pipe_print/pipe_printer_data.ps. You can test this by
running as the 'lp' user:
========================
# su lp
phew.
Ok, back to the Yast printer dialog: in the "Printing to Pipe" screen,
enter the full path to the script you just created and click "Next"
Enter a printer name, something like "virtual_printer" or "pipe_printer"
or whatever. Un-check "do local filtering" !
Click "next", then try testing the printer with the "test" button. Note
this won't print anything, it will just send data to the
/tmp/pipe_print/pipe_printer_data.ps file - view this file to check if
you are getting postscript output.
That should be all you need to make the virtual printer - and most
applications can fairly easily be told to print to it. But you need a
way to send this postscript to the 4-up printer queue (or wherever) -
hence the next step:
(C) a script to print via kprinter
You can actually do this from the command line trivially:
kprinter /tmp/pipe_print/pipe_printer_data.ps
However it can be worth setting up a simple script to do this:
====================
#!/bin/sh
gs /tmp/pipe_print/pipe_printer_data.ps
kprinter /tmp/pipe_print/pipe_printer_data.ps
====================
The "gs" command is there for a very-rapid preview - on my machine it
rapidly displays every page in the file to be printed, which gives me
slight satisfaction that I know roughly what is being printed, and how
many pages. YMMV, this line is completely redundant.
The 'kprinter' command pops up the 'kprinter' dialog, letting me choose
a printer queue, like the one I chose above.
I put this script on a toolbar button so I can quickly send my last
print job to a printer.
Some general observations - this is a hack, I'd love to know how to skip
the two-stage process, but I haven't worked out how. The trouble is
that the print command runs as 'lp' but the kprinter command needs to
run as the current user (or at least have access to X) and I ran out of
time to work out how to do this.
Also, I'd like a better preview mechanism than 'gs', but I have problems
with the KDE ghostscript viewer and the postscript output of Acrobat.
This could obviously be improved :)
Anyway, it is useful for me, I hope it is useful for others.
- Korny
--
Kornelis Sietsma e-mail: korny at my surname dot com