From: aas@rosmer.nr.no (Gisle Aas)
Subject: Re: Showing EPS files in Framemaker
Reply-To: Gisle.Aas@nr.no
Organization: Norwegian Computing Centre, Oslo, Norway
Date: Mon, 5 Oct 1992 09:42:51 GMT

In article <MFISHER.92Oct3131053@primate.atl.ge.com> mfisher@atl.ge.com (Michael Fisher) writes:


>     Is there any program out there that can take an EPS file that does not
>   have a preview bitmap and insert one in the file.  Some script using
>   ghostscript or another postscript renderer should be able to do this and I
>   had though about writing something but do not really have the time.

The 'eps2epsi' program does the job!  You will need perl & ghostscript!

#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 10/05/1992 09:34 UTC by aas@boeygen
# Source directory /nr/boeygen/u2/aas/eps2epsi
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   5005 -rwxr-xr-x eps2epsi
#
# ============= eps2epsi ==============
if test -f 'eps2epsi' -a X"$1" != X"-c"; then
	echo 'x - skipping eps2epsi (File already exists)'
else
echo 'x - extracting eps2epsi (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'eps2epsi' &&
#!/usr/local/bin/perl
'di';
'ig00';
X
# EPSI file generator. Written by Gisle Aas, NR, 1991
# Converts all types of EPS-files to the EPSI format where a bitmap preview
# is included. You need GhostScript to render the bitmaps for you.
X
# $Log: eps2epsi,v $
# Revision 1.4  1992/09/08  17:41:27  aas
# Some applications makes real (not integer) boundingbox coordinates, despite
# what the DSC says.  These applications should really be fixed.  But while we
# wait for that to happen....
#
# Revision 1.3  1992/08/25  14:56:05  aas
# Hvis kommentarene i begynnelsen ikke sluttet med %%EndComments, s spiste
# vi opp frste linje av postscript koden.
#
# Revision 1.2  1992/07/30  13:32:19  aas
# Oppdatert for GhostScript versjon 2.4.  Det var ny syntaks for
# makeimagedevice.
#
# Revision 1.1  1991/05/28  09:18:04  aas
# Initial revision
#
X
$prog_name = substr($0,rindex($0,"/")+1);
require 'getopts.pl';
unless (&Getopts('w:')) {
X  print STDOUT "Usage: $prog_name [-w <preview width>] [<file>]\n";
X  exit 1;
}
X
die 'To many files' if ($#ARGV > 0);
X
@epsfile = <>;			# slurp
die 'Not PostScript file' unless ($epsfile[0] =~ /^%!PS-Adobe-/);
X
# Get the dimensions of the picture
for (@epsfile) {
X   ($llx, $lly, $urx, $ury) =
X      /^%%BoundingBox:\s*(-?[0-9\.]+)\s+(-?[0-9\.]+)\s+(-?[0-9\.]+)\s+(-?[0-9\.]+)/;
X   last if defined($llx);
}
die "No %%BoundingBox found in file" unless defined($llx);
X
# Calculate 
$preview_width = int(($opt_w || 79) / 2) * 8;
$width  = $urx - $llx + 1;
$height = $ury - $lly + 1;
$scalefactor = $preview_width / $width;
$width  = int($width * $scalefactor);
$height = int($height * $scalefactor);
X
# Produce GhostScript program
$gsfile = "/tmp/gs$$.tmp";
open(GSFILE, ">$gsfile") || die "Can't write to file $gsfile";
print GSFILE <<"---EndGhostScriptProgram---";
%!GhostScript
/BITIMAGE_WIDTH $width def
/BITIMAGE_HEIGHT $height def
/BITIMAGE_FILE (%stdout) def
X
%---- Setup a memory device --------
[1 0 0 -1 0 BITIMAGE_HEIGHT]
BITIMAGE_WIDTH BITIMAGE_HEIGHT
%
% [1 1 1 rgbcolor 0 0 0 rgbcolor] <-- 2.3 arguments
% <ff 00>                         <-- 2.4 arguments from ghost@aladdin.com
%
<ff 00> 
makeimagedevice
setdevice
X
%--- Some transformations
/showpage {} def
$scalefactor dup scale
$llx neg $lly neg translate
X
%--- The old EPS file
@epsfile
X
%---- Print bitmap on a file -------
/line BITIMAGE_WIDTH 8 idiv 1 add string def
/output BITIMAGE_FILE (w) file def
output (---------) writestring
output 10 write
0  1  BITIMAGE_HEIGHT 1 sub { %for
X   output (%) writestring
X   currentdevice exch
X   line copyscanlines
X   output exch writehexstring
X   output 10 write
} for
output flushfile
quit
---EndGhostScriptProgram---
X
close GSFILE;
close STDIN;	# so that GhostScript can't read it.
X
@gsoutput = `gs -q -DNODISPLAY $gsfile`;   # run GhostScript
die "Can't run GhostScript" unless $? == 0;
unlink $gsfile;
X
@preview = grep(/^-----/ .. 1, @gsoutput);   # remove GhostScript garbage
shift(preview);
if ($#preview < 0) {
X  print STDERR "GhostScript gives no output for the specified file\n";
X  print STDERR @gsoutput;
X  exit 1;
}
X
print shift(epsfile);
$_ = shift(epsfile);
while (/^%%/) {
X  if (/^%%BoundingBox:/) {
X    print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
X    $boundingbox = 1;
X  } elsif (/^%%EndComments/) {
X    last;
X  } else {
X    print;
X  }
X  $_ = shift(epsfile);
}
print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
print "%%EndComments
%%BeginPreview: $width $height 1 $height\n";
print @preview;
print "%%EndPreview\n";
X
print $_ unless /^%%/;
print grep(!(/^%%BeginPreview:/ .. /^%%EndPreview/) && !/^%%BoundingBox:/,
X	   @epsfile);
X
X
X
X
X
###########################################################################
X	# These next few lines are legal in both Perl and nroff.
X
.00;			# finish .ig
X 
'di			\" finish diversion--previous line must be blank
.nr nl 0-1		\" fake up transition to first page again
.nr % 0			\" start at page 1
';<<'.ex'; #__END__ #### From here on it's a standard manual page #########
.TH EPS2EPSI 1 "May 1991"
.SH NAME
eps2epsi \- Filter for inclusion of a preview in an EPS file
.SH SYNOPSIS
.B eps2epsi
[
.B \-w
.I preview_width
] [
.I filename
]
.SH DESCRIPTION
.B Eps2epsi
puts a preview section in a PostScript file (preferably EPSF).
The preview produced
is in the encapsulated PostScript interchange format (EPSI)
suitable for import by FrameMaker and other document composing
systems.
.B Eps2epsi
reads the file specified (or standard input) and sends the new file
with the preview included to standard output.
.PP
.B Esp2epsi
uses
.B GhostScript
to render the preview bitmap, which means that
.B GhostScript
must be installed at your system before you can use
.B eps2epsi.
.SH OPTIONS
.TP 5
.BI \-w " n"
Set the width (in characters) of the preview section. This also specifies the
resolution of the preview as
.I n
times 4 horizontally.
.SH SEE ALSO
.BR perl (1),
.BR gs(1)
.SH AUTHOR
Gisle Aas, Norwegian Computing Center (NR), Oslo, Norway.
<Gisle.Aas@nr.no>
.ex
SHAR_EOF
chmod 0755 eps2epsi ||
echo 'restore of eps2epsi failed'
Wc_c="`wc -c < 'eps2epsi'`"
test 5005 -eq "$Wc_c" ||
	echo 'eps2epsi: original size 5005, current size' "$Wc_c"
fi
exit 0
--
Gisle Aas               |  snail: Boks 114 Blindern, N-0314 Oslo, Norway
Norsk Regnesentral      |  X.400: G=Gisle;S=Aas;O=nr;P=uninett;C=no
voice: +47-2-453561     |  inet:  Gisle.Aas@nr.no