Take the 2-minute tour ×

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?

use LWP::Simple;
use HTML::HTMLDoc;
use CGI;
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($!);
print "</body></html>";
share|improve this question
add comment

1 Answer

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).
share|improve this answer
add comment

Your Answer

