I want to print a book on a laser printer, so I have prepared a PostScript file ready for printing, with reordered and 2-up'ed pages. Now I want to add booklet marks on appropriate pages, like on the following picture:
From other SO questions I know that its showpage
command that separates individual pages in PS file, so I wrote simple Perl script which counts showpage
's occurences and prepends PostSript code if necessary, just to test if this approach works:
#!/usr/bin/env perl
use strict;
use warnings;
my $bookletSheets = 6;
my $occurence = 1;
while (my $line = <>) {
if ($line !~ /^showpage/) {
print $line;
next;
}
my $mod = $occurence % (2*$bookletSheets);
if ($mod == 1) {
print " 1 setlinewidth\n";
print " 5 5 newpath moveto\n";
print "-5 5 lineto\n";
print "-5 -5 lineto\n";
print " 5 -5 lineto\n";
print " 5 5 lineto\n";
print "0 setgray\n";
print "stroke\n";
print "%NOP\n"
}
print $line;
$occurence++;
}
But after running:
$ cat book.ps | ./preprocess.pl > book-marked.ps
I can see no signs of additional marks in document viewer, despite the code got injected correctly. What have I done wrong?
There are some links I've based my thinking on: