Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to make work HTML::HTMLDoc on browser?

by rnewsham (Curate)
on Apr 16, 2013 at 07:03 UTC ( [id://1028827]=note: print w/replies, xml ) Need Help??


in reply to How to make work HTML::HTMLDoc on browser?

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');

Replies are listed 'Best First'.
Re^2: How to make work HTML::HTMLDoc on browser?
by elavarasan (Acolyte) on Apr 16, 2013 at 07:25 UTC

    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?

        no in command line no error it generates valid pdf

        Hi rnewsham , I have the same issue with elavarasan. Please help me solve it. I've been working on this for more than a week now. Please see my codes below

        #!/usr/bin/perl5 use HTML::HTMLDoc; use strict; use warnings; use CGI; my $cgi=new CGI; print $cgi->header( -type => 'application/pdf' ); my $htmldoc = new HTML::HTMLDoc('mode'=>'file', 'tmpdir'=>'/tmp'); $htmldoc->set_permissions('all'); $htmldoc->set_html_content(qq~<html><body><table border=1><tr><td cols +pan=2>A PDF file</td></tr><tr><td>Column 1</td><td><img src='freight- +charge.jpg'></td></tr></table></body></html>~); # $htmldoc->set_input_file($filename); # alternative to use a present +file from your fs my $pdf = $htmldoc->generate_pdf(); print $pdf->to_string(); $pdf->to_file('foo.pdf');

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1028827]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-25 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found