tags:

views:

163

answers:

1

Task Have a CGI-script which produces an .*pdf file from the html-content/page

Problem: When launched from the web browser, there is no creation of the pdf document.

Steps So far:

  • chmod settings set to above recommended (777)
  • tested normal output to file from the script, which works fine
  • when run locally on the server from the command line, the *.cgi script works

Question: Why does the script not work when run from the web browser?

#!/usr/bin/perl
use LWP::Simple;
use HTML::HTMLDoc;
use CGI;
print "Content-type: text/html\n\n";
print "<html><head><title>test</title></head>";
print "<body>";

my $htmldoc->set_html_content(qq~<html><body>A PDF file</body></html>~);
my $pdf = $htmldoc->generate_pdf() or die($!);
$pdf->to_file('/var/www/tom.pdf');
print "</body></html>";
A: 

Where do you send the generated file to the browser?

Note that you cannot embed PDF in HTML; you must either

  • put the file in a place where your web server will deliver it and send a link to the file to the browser
  • or set the content type to application/pdf and just return the file (without any HTML tags around it).
Aaron Digulla