elavarasan has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl # use strict; use CGI; my $cgi=new CGI; print $cgi->header; use HTML::HTMLDoc; my $htmldoc = new HTML::HTMLDoc(); $htmldoc->set_html_content('<html><body>A PDF file</body></html>'); # $htmldoc->set_input_file("/public_html/voslegal/legal/transactionact +ive/joselawfirm/transactionactive/independent-case/documents/temp.htm +l"); # alternative to use a present file from your fs my $pdf = $htmldoc->generate_pdf(); print $pdf->to_string(); $pdf->to_file('/vos/spain/newpdfdoc.pdf');

Replies are listed 'Best First'.
Re: How to make work HTML::HTMLDoc on browser?
by marto (Cardinal) on Apr 16, 2013 at 06:58 UTC

    You are printing a HTTP header, but not specifying the content type, so it's defaulting to text/html. A PDF is neither text or HTML.

    print $cgi->header("Content-type: application/pdf");

    This is explained in the links I gave you over a week ago when you asked in the chatterbox, before you showed any code. Even if you only read the troubleshooting section Getting Your CGI Scripts Working it explains this.

Re: How to make work HTML::HTMLDoc on browser?
by rnewsham (Curate) on Apr 16, 2013 at 07:03 UTC

    I have tweaked your code and this works for me. Remember to use strict and warnings especially important if you have an error but nothing is appearing in the logs. For delivering a pdf to a browser you need a content type header.

    #!/usr/bin/perl use strict; use warnings; use CGI; my $cgi=new CGI; print $cgi->header( -type => 'application/pdf' ); use HTML::HTMLDoc; my $htmldoc = new HTML::HTMLDoc(); $htmldoc->set_html_content('<html><body>A PDF file</body></html>'); my $pdf = $htmldoc->generate_pdf(); print $pdf->to_string(); $pdf->to_file('newpdfdoc.pdf');

      while using you code it returns following error File does not begin with '%PDF-',

        It sounds like your problem may be with the install of htmldoc on your system. Are you able to use htmldoc from the command line to generate a valid pdf? Are there any errors reported in the logs from my example code?

Re: How to make work HTML::HTMLDoc on browser?
by davido (Cardinal) on Apr 16, 2013 at 06:27 UTC

    What error messages are you seeing in your server's log?


    Dave

      it is not giving any error but it returns empty pdf file 0 byte

        This code is generating the blank pdf file.