From: Mark.McIntosh@engr.UVic.CA (Mark  McIntosh)
Subject: Re: How do I change postscript resumes into ASCII so I can print and kee
Organization: University of Victoria, Victoria, BC, Canada
Distribution: na
Date: 11 Sep 92 18:57:40 GMT

On Fri, 11 Sep 92 09:23:32 PDT, jtrumbull@coast.almanac.bc.ca (Jim Trumbull    ) said:
>The problem that we are having is that some of the resumes we receive
>are in postsript format, and so far, are not usable.  Please let me
>know what has to be done to convert these to ASCII - that is, if it
>is at all possible.

It's not straightforward, but here are two UNIX based suggestions I've
seen:

1) A sed(1) macro, defined as a C-shell alias

alias unps \(sed \
 \''s/%.*$//g;s/^[ \t]*[^()]*$//g;s/^[^(]*(//g;s/)[^(]*(/ /g;s/)[^)]*$//g;'\' \
 \| tr '\\012' '\\040' \| tr -s '\\040' '\\040' \; echo \'\'\)

invoke as "unps < filename".  Will dump Postscript text strings found.

2) A Perl program

#!/usr/unsupported/perl
# We simulate a postscript interpreter (gack!)
# Skip the leading glop
#
#From: rjc@onion.princeton.edu (Raymond Chen)
#Date: 20 Mar 92 22:36:32 GMT
#
#Every twenty-five requests for a Postscript-To-Ascii filter I see,
#I post this.  This was tailored for the Postscript that comes out of groff.
#We actually simulate a (dumbed down) Postscript interpreter!
#It's been so long, I can't remember if the code satisfactorily handles kerns.
#
#I used this script to de-Postscriptify a 1Meg postscript file.
#
#Unlike my previous dastardly perl script, this one actually has
#comments!  (Not very useful ones, of course.)

while (<> !~ /^%%Page: 1 2/) { ; }

@stack = ();
$y = 0;

main: while(<>){ chop;
while (s/\\$//) { $_ .= <>; chop; }
next if /^%/;
s/\\\(/\\050/g;
s/\\\)/\\051/g;
  while ($_) {
  s/^\s*//;#nuke leading whitespace
  if (s/^([\d.-]+)//) { # a number
  push(@stack, $1); }
  elsif (s/^\/[@_a-zA-Z-]+//) { # a literal
    push(@stack, ""); }
  elsif (s/^\(([^)]*)\)//) { # a string
    push(@stack, $1); }
  elsif (s/^(\w+)//) { # a command
    $c = $1;
    if ($c eq "C") { print &spaceout($stack[2]); }
    elsif ($c eq "E") { print "~" if $stack[1] > 0; print &fixup($stack[0]); }
    elsif ($c eq "F") { print &fixup($stack[1]); }
    elsif ($c eq "F2") { ; }
    elsif ($c eq "G") { print &spaceout($stack[1]); }
    elsif ($c eq "H") { print &fixup($stack[2]); }
    elsif ($c eq "Q") { &moveshow; }
    elsif ($c eq "R") { shift(@stack); &moveshow; }
    elsif ($c eq "S") { shift(@stack); &spaceout($stack[0]); &moveshow; }
    elsif ($c eq "T") { shift(@stack); shift(@stack); &moveshow; }
    elsif ($c eq "BP") { }
    elsif ($c eq "EP") { print "\n", "-" x 40, "\n"; }
    elsif ($c eq "SF") { }
    elsif ($c eq "end") { last main; }
  else { print STDERR "\7", join(":", @stack), " <$c>?\n"; }
  @stack = ();
  }
  elsif (s/^<(.*)>//) { # a hex string
     $c = ""; $d = $1;
     while ($d =~ s/(..)//) { $c .= sprintf("%c", hex($1)); }
    push(@stack, $c); }
  else { print STDERR "\7How to parse $_?\n"; }
  }
  }

sub moveshow {
	if ($y != $stack[2]) { $y = $stack[2]; print "\n"; }
	else { print "~"; }
	print &fixup($stack[0]); 
}

sub spaceout { @t = split(//, $_[0]); $_[0] = &fixup(join(" ", @t)); }

sub fixup { $_[0] =~ s/\.\.\.\.[.]*/\.\.\.\./; 
$_[0] =~ s/\\(\d\d\d)/sprintf("%c",oct($1))/eg;
$_[0] =~ s/\214/fi/g; $_[0] =~ s/\215/fl/g; 
$_[0]; }

Newsgroups: bc.general