#!/usr/local/bin/perl -w # # Example 11-2. A CGI script that generates PostScript 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!"; # Generate a PostScript invoice my $lines = new PostScript::Elements; # First add a 2 pt line with a 36 pt margin 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 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/2002"; # 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 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;