Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

html::htmldoc not working

by divinafaudan (Initiate)
on Aug 01, 2013 at 15:12 UTC ( #1047471=perlquestion: print w/replies, xml ) Need Help??
divinafaudan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am really confuse why does my codes did not work when tried to run it from the browser.However, it works perfectly when run from the command line. 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(); $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');

I am getting no error, when i compiled it, the syntax is OK. Please help

Replies are listed 'Best First'.
Re: html::htmldoc not working
by choroba (Bishop) on Aug 01, 2013 at 15:22 UTC
    CGI scripts are usually run as a different user (www-data etc.) HTML::HTMLDoc uses an external programme, htmldoc. Are you sure this user has permissions to run it? What do the logfiles say?
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks for your reply. I guess the user has permission to run the program because the file was set to 777 mode and the program able to generate the pdf with 0 bytes. I forgot to mention in my last post that the program generated pdf,and, the problem is it did not write the pdf content.

        I did not mean your script, but the htmldoc programme (use
        type htmldoc
        in a shell to find its location).
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: html::htmldoc not working
by rpnoble419 (Pilgrim) on Aug 01, 2013 at 20:07 UTC

    You are not passing the name of the PDF file back to the browser to open. You may want to try adding this as the last line of your file

    print $cgi->redirect('foo.pdf');

    You will need to remove the print $cgi->header for the redirect to work...

      Thanks for your reply but do redirection did not solve the issue. Do you have any other idea? I do not need to open the pdf file from the browser, I just want to create the pdf file and able to write on it. But I do appreciate your help, really.
Re: html::htmldoc not working
by glasswalk3r (Friar) on Aug 02, 2013 at 21:30 UTC

    I think you should just quit using HTML::HTMLDoc in a CGI environment: you will need to fork from the web server and that is never good, both for performance and security.

    I cannot give a suggestion about what to look for in CPAN, but probably there are modules there to write PDF without the need to fork.

    Alceu Rodrigues de Freitas Junior
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1047471]
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-05-25 02:27 GMT
Find Nodes?
    Voting Booth?