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. Advertisements

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. dont bother
    Replies:
    0
    Views:
    1,087
    dont bother
    Mar 3, 2004
  2. keto
    Replies:
    0
    Views:
    1,361
  3. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    634
    David Cournapeau
    Dec 30, 2008
  4. Phil
    Replies:
    4
    Views:
    1,001
    Gabriel Genellina
    Jan 17, 2010
  5. Ian
    Replies:
    2
    Views:
    2,764
  6. J M
    Replies:
    2
    Views:
    286
    Darren Dunham
    Jan 26, 2004
  7. Replies:
    2
    Views:
    232
    John W. Krahn
    Nov 27, 2006
  8. iMath
    Replies:
    2
    Views:
    288
    Peter Otten
    Dec 26, 2012
Loading...