| Rob Mahurin on Mon, 25 Feb 2002 18:41:40 +0100 (CET)(envelope-from owner-apsfilter-help@apsfilter.org) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| fake duplex page reordering? [patch] |
Hello,
I have an HP Deskjet (693C, fwiw) in which the pages come out of the
printer face up and so wind up in reverse order relative to how the
were printed: the first page printed ends up on the bottom of the
stack, the last on the top. I have been "fake duplex" printing using
a script like
<code snippet>
psselect -e $fname | lp
# surely there's a better way to determine the total number of pages
[ x$(( $(psselect -p_1 $fname 2>&1 > /dev/null\
| tr "[]" " \n" | head -1 ) % 2 ))x == x1x ] &&
echo "[0] Wrote (almost) blank page, 2 bytes" &&
echo . | lp
echo -n "Press enter to print the odd pages ..."
read;
psselect -or $fname | lp
</code snippet>
i.e., print the even pages, print a blank page if there are more odds
than evens (giving me page 2 on the bottom, last even page on top or a
blank if need be), let me stuff that stack of paper back in the feeder
tray, and the print the odd pages in reverse order. This give me a
properly-ordered document with page 1 at the top, ready to staple with
no reshuffling. The problems are that I have to convert whatever it
is to Postscript, with honest page numbers.
I have just discovered apsfilter and its fake duplex option, which
does the conversion cruft for me and has a much nicer restarting
mechanism, which I like. Unfortunately it doesn't reverse the odd
pages, which means that I have to reorder all of the pages twice
(once feeding them back in for the odd sides, and again before
stapling them). I am lazy and dislike this. :) How to fix it?
I've poked around and not found any documentation for this, and
looking at the source (/usr/share/apsfilter/bin/apsfilter on my Debian
woody system, with apsfilter 6.1.1) it seems that the
print_ps_duplex() function works essentially the same way as mine
(always refreshing). It seems that the way to change it would be
to add a DUPLEX_REVERSE option to the option set (in apsfilterrc?) and
change print_ps_duplex() to print the extra blank page if
the last page is odd and reverse the odd pages if DUPLEX_REVERSE is
set.
The first is a little tricky. I don't really like my kludge for
discovering the parity of the last page, but can't think of a prettier
way to do so. It looks like the code to add after the if statment
inside the even-printing subshell would be
[ "$DUPLEX_REVERSE" -a \
x$(( $(psselect -p_1 "$APS_TMPDIR/duplex.ps" 2>&1 > /dev/null\
| tr "[]" " \n" | head -1 ) % 2 ))x == x1x ] && \
echo . | print_ascii
but that breaks your non-dependence on psselect and I'm not sure that
the blank page would make it into the file copy-even. In fact, I'm
sure not, since that gets done in print_data. Would it be safe to
change the tee "$APS_TMPDIR/copy-$SAVE_DUPLEX_COPY" | print_copy
in print_data to a tee --append? or perhaps
local flag;
[ "$DUPLEX_REVERSE" -a "SAVE_DUPLEX_COPY" ] &&
flag=-a
tee $flag "$APS_TMPDIR/copy-$SAVE_DUPLEX_COPY" | print_copy
I guess that's a question of how safely the temporary directories are
created.
The second piece is straightforward to do: change the section
where the odd pages are printed to something like
local flag
if find_filter psselect; then
[ "$DUPLEX_REVERSE" ] && flag=-r
psselect -q -o $flag < "$APS_TMPDIR/duplex.ps"
else
# pstops exists, otherwise we wouldn't be here (see above)
[ "$DUPLEX_REVERSE" ] && flag=-
pstops -q 2:${flag}0 < "$APS_TMPDIR/duplex.ps"
fi | print_ps
I have just implemented these changes on my own system and they seem
to work, so I'll dignify this message by calling it a "patch". It's
not complete because you need to tell the user when to use
DUPLEX_REVERSE, but I don't think it's all that bad for a morning's
effort.
Thanks for writing such clear code, by the way.
Please CC: me on any replies, as I'm not on this list.
Rob
--
Honesty's the best policy.
-- Miguel de Cervantes