C
Carsten Thomas
Hi there,
I have a couple of postscript files that do not print any hints to the
origin of the file. I therefore tried to extract information as
filetitle and date of creation from the file headers and print them.
For this first attempt of manipulation the ps-code I made my first
steps into perl. And in fact it does more or less what I want but does
not produce clean postscript code.
I insert the extracted data just after each %%Page: line as I did not
find a way to make the while (/^%%/) command work correctly. Thus as
long as there are no further %%lines after this, everything seems to
work fine. Otherwise an "invalid restore" error is produced and the
stack contains exactly the chars I inserted into the file prceded by a
"savetype".
Couly anybody give me a hint what to change in this script?
Thanks a lot,
Carsten
#!/usr/bin/perl
while (<>) {
if (/^%%Page:/) {
print $_;
$Page=substr($_,8);
$Page=substr($Page,0,(length($Page)-2));
print "/Helvetica findfont 12 scalefont setfont\n";
print "9 216 exch moveto ";
print "(file:";
print $file;
print ") dup \n";
print "show\n";
print "9 27 exch moveto\n";
print "(created: ";
print $Creation;
print ") dup \n";
print "show\n";
print "9 396 exch moveto\n";
print "(page: ";
print $Page;
print ") dup \n";
print "show\n";
} elsif (/^%%CreationDate:/) {
$Creation=substr($_,20);
} elsif (/^%%Title:/) {
$Datei=substr($_,9);
} elsif (/^%%Creator:/) {
$Creator=substr($_,11);
} else {
print;
}
}
I have a couple of postscript files that do not print any hints to the
origin of the file. I therefore tried to extract information as
filetitle and date of creation from the file headers and print them.
For this first attempt of manipulation the ps-code I made my first
steps into perl. And in fact it does more or less what I want but does
not produce clean postscript code.
I insert the extracted data just after each %%Page: line as I did not
find a way to make the while (/^%%/) command work correctly. Thus as
long as there are no further %%lines after this, everything seems to
work fine. Otherwise an "invalid restore" error is produced and the
stack contains exactly the chars I inserted into the file prceded by a
"savetype".
Couly anybody give me a hint what to change in this script?
Thanks a lot,
Carsten
#!/usr/bin/perl
while (<>) {
if (/^%%Page:/) {
print $_;
$Page=substr($_,8);
$Page=substr($Page,0,(length($Page)-2));
print "/Helvetica findfont 12 scalefont setfont\n";
print "9 216 exch moveto ";
print "(file:";
print $file;
print ") dup \n";
print "show\n";
print "9 27 exch moveto\n";
print "(created: ";
print $Creation;
print ") dup \n";
print "show\n";
print "9 396 exch moveto\n";
print "(page: ";
print $Page;
print ") dup \n";
print "show\n";
} elsif (/^%%CreationDate:/) {
$Creation=substr($_,20);
} elsif (/^%%Title:/) {
$Datei=substr($_,9);
} elsif (/^%%Creator:/) {
$Creator=substr($_,11);
} else {
print;
}
}