How to Create PDF from HTML using perl
Posted
by Octopus
on Stack Overflow
See other posts from Stack Overflow
or by Octopus
Published on 2010-03-29T08:01:31Z
Indexed on
2010/03/29
8:03 UTC
Read the original article
Hit count: 551
I need to create a PDF file from the html I have created usign rrdcgi. This page contains the details and graphs in png format. I have written the below code using perl module HTML::HTMLDoc to create a pdf file using saved html file. The images are of size width 1048 and hight 266 but when creating a pdf file the images are not shown completly from the right side.
#!/usr/bin/perl
use strict;
use warnings;
use HTML::HTMLDoc;
my $filename = shift;
my $htmldoc = new HTML::HTMLDoc();
$htmldoc->set_input_file($filename);
$htmldoc->no_links();
$htmldoc->landscape();
$htmldoc->set_jpeg_compression('50');
$htmldoc->best_image_quality();
$htmldoc->color_on();
$htmldoc->set_right_margin('1', 'mm');
$htmldoc->set_left_margin('1', 'mm');
$htmldoc->set_bodycolor('#FFFFFF');
$htmldoc->set_browserwidth('1000');
my $pdf = $htmldoc->generate_pdf();
print $pdf->to_string();
$pdf->to_file('foo.pdf');
I need help on following items: 1) How to display the complete image on page. 2) How to set a link on html page to create pdf file with the contents on the current page.
Any help with the perl code would be really appreciated.
© Stack Overflow or respective owner