Chapter 11
100 50 moveto
100 100 lineto
50 100 50 0 180 arc
37.5 100 37.5 180 360 arc
50 100 25 0 180 arc
37.5 100 12.5 180 360 arc
.5 setgray
8 setlinewidth
stroke
showpage
#!/usr/bin/perl -w
#
# Using Image::Magick to embed a graphic (as an EPS) within
# a PostScript file
#
use Image::Magick;
my $image = Image::Magick->new;
# Read in a graphic
#
$image->Read('gif:quahog.gif');
# Set the x, y coordinate for the lower left hand corner
# of the graphic with the 'page' attribute. See chapter 5 for
# more details on Image::Magick...
#
$image->Set(page => '+100+200');
# Write out the image to a temporary EPS file, since we
# cannot transfer the EPS code directly to a scalar with Image::Magick
#
$image->Write('eps:quahog.eps');
# Open the temporary file and read in the EPS code
#
open(EPS, 'quahog.eps') or die "Couldn't open quahog.eps: $!";
undef $/;
my $eps = <EPS>;
close EPS;
# Open the output file and write out the PostScript code
# with the embedded EPS...
#
open(OUT, '>psoutput.ps') or die "Couldn't open psoutput.ps: $!";
print OUT <<EndPrint;
/Times-Roman findfont 48 scalefont setfont
100 150 moveto
(This is an EPS graphic) show
EndPrint
print OUT $eps;
print OUT "showpage\n";
close OUT;
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html">
<TITLE>Apocabilly Records Order Form</TITLE>
</HEAD>
<BODY>
<TABLE CELLSPACING=0 BORDER=0>
<TR><TD VALIGN="TOP">
<P>
<IMG SRC="apocabilly2.gif" WIDTH=287 HEIGHT=96
ALT="Apocabilly Records, Since 1998></P>
</TD>
<TD VALIGN="TOP">
<H1>Order Form</H1>
<H2>Order Your Favorite Apocabilly Records Here!</H2>
<P>All orders shipped within 2 working days, COD.</P>
<FORM ACTION="cgi-bin/processorder.cgi" METHOD="POST">
<P>Name:<BR>
<INPUT TYPE="text" MAXLENGTH="80" NAME="name">
<BR>
Address:<BR>
<INPUT TYPE="Address" MAXLENGTH="80" NAME="address">
<BR>
City/State/Zip:<BR>
<INPUT TYPE="text" MAXLENGTH="80" NAME="citystatezip">
</P><P>
<STRONG>Your shopping cart contains the following items:</STRONG>
</P><P>
(1) The Buck Buck Brothers sing Esperanto Love Songs @$12 <BR>
(2) The BeatLess: Meet the BeatLess @$12 <BR>
(1) Old Tyme Tin Can Banjo Tunes @$5
</P><P>
<INPUT TYPE="hidden" NAME="merchandise" VALUE="(1) The Buck Buck Brothers sing
Esperanto Love Songs @$12 \n(2) The BeatLess: Meet the BeatLess @$12 \n
(1) Old Tyme Tin Can Banjo Tunes @$5 \n">
</P><P>
<STRONG>Your total order comes to: $41</STRONG></P>
<P>
<INPUT TYPE="hidden" NAME="total" VALUE="$41">
<INPUT TYPE="submit" VALUE="Order Now!" >
</P>
</FORM>
</TD></TR>
</TABLE>
</BODY>
</HTML>
#!/usr/local/bin/perl
use CGI;
use PostScript::TextBlock;
use PostScript::Elements;
# Get the parameters passed into the script
#
my $query = new CGI;
my $name = $query->param('name');
my $address = $query->param('address');
my $citystatezip = $query->param('citystatezip');
my $merchandise = $query->param('merchandise');
my $total = $query->param('total');
# Do whatever needs to be done to place an order here...
# If it is successful, continue...
print $query->header(-type => 'text/html');
print $query->start_html(-title => "Order completed!");
print "Your order has been placed. Thanks!";
# Now let's generate a PostScript invoice to complete this example...
#
my $lines = new PostScript::Elements;
# First add a 2 pt border with a 36 pt border around the page
#
$lines->addBox(points => [36,756, 540, 720],
linewidth => 2);
# Now draw the line dividing the title and the address section
#
$lines->addLine(points => [46,650, 566,650]);
# Finally, draw the line separating the address and order sections
#
$lines->addLine(points => [46, 550, 566,550]);
# Altogether there are five discrete block of text, so we will need
# five TextBlock objects...
#
my $tb = new PostScript::TextBlock;
my $tb2 = new PostScript::TextBlock;
my $tb3 = new PostScript::TextBlock;
my $tb4 = new PostScript::TextBlock;
my $tb5 = new PostScript::TextBlock;
my $date = "10/21/2001"; # We'll hard-code the date; that's one way
# to avoid Y2K problems :)
# Now add the text to the various text blocks
#
$tb->addText(text => "Apocabilly Records\n",
size => 48, leading => 56);
$tb->addText(text => "Ordered on $date\n",
size => 24, leading => 30);
$tb2->addText(text => "SHIP TO:\n $name\n $address\n $citystatezip\n",
size => 14,
leading => 18 );
$tb3->addText(text => "FROM:\n Apocabilly Records\n 1249 Foo St.\n".
" Hoosick Falls, NY 51209\n",
size => 14,
leading => 18 );
$tb4->addText(text => "YOUR ORDER:\n\n$merchandise",
size => 16, leading => 30);
$tb5->addText(text => "TOTAL: $total",
size => 16, leading => 30);
# Then generate the code by calling the Write() method for each object
#
my $code = $lines->Write();
# The Write() method for a TextBlock returns a list containing the
# code and the remainder that didn't fit in the specified region.
# In this example, we will discard the remainder, only taking the code
# and appending it to the code generated thus far.
#
$code .= [$tb->Write(530, 100, 46, 756)]->[0];
$code .= [$tb2->Write(260, 130, 46, 640)]->[0];
$code .= [$tb3->Write(260, 130, 306, 640)]->[0];
$code .= [$tb4->Write(530, 480, 46, 560)]->[0];
$code .= [$tb5->Write(260, 30, 306, 76)]->[0];
# Write the PostScript code to the file called invoice.ps
# in a real system, this should be a unique filename
#
open OUTFILE,">invoice.ps" or die "Couldn't open invoice.ps: $!";
print OUTFILE $code;
close OUTFILE;