print file information from postscript headers

Discussion in 'Perl Misc' started by Carsten Thomas, Nov 9, 2005.

  1. 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;
    }
    }
     
    Carsten Thomas, Nov 9, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green
    Replies:
    0
    Views:
    1,134
    Roedy Green
    Aug 2, 2003
  2. keto
    Replies:
    0
    Views:
    1,022
  3. J M
    Replies:
    2
    Views:
    174
    Darren Dunham
    Jan 26, 2004
  4. Replies:
    2
    Views:
    161
    John W. Krahn
    Nov 27, 2006
  5. iMath
    Replies:
    2
    Views:
    164
    Peter Otten
    Dec 26, 2012
Loading...

Share This Page