Conversion of HTML to PDF with Perl

Published: January 21, 2009

Antano Solar John is the creator and developer of the most advanced technologies to design and fast-track personal evolution and an investor in startups that have access to cutting-edge solutions for personal excellence.

I have attached a perl script to convert HTML to PDF

htmltopdf

Following is the code for the same

use HTML::HTMLDoc;

my $htmldoc = new HTML::HTMLDoc();
$htmldoc->set_input_file(“source.html”); # alternative to use a present file from your fs
my $pdf = $htmldoc->generate_pdf();
$pdf->to_file(‘foo.pdf’);

It actually works perfectly fine even if the HTML is not w3 validated. Neat if you have to convert HTML that was not created by you on the fly to PDF.

I also acknowledge that the same code is there in the CPAN’s synopsis of the module used. But it took me a few hours to locate it and to pick from the zillion other modules available there. Hope someone finds it useful.

If you are wondering why I posted this at such an ODD time. I was clearning out my notes and inbox items and saw a note to myself to post this in a blog. Horrors of GTD when the weekly reviews are not done! And as always if the task aint more than 2 mins, it aint worth putting in a to do list. And hence the post.

Related Posts

Rails on Lion

Rails on Lion

Ruby HTTP Post with JSON Request + SSL + Certificate + Basic Authentication

Ruby HTTP Post with JSON Request + SSL + Certificate + Basic Authentication

Tools & Showcase

Tools & Showcase

5 Min Mentor – Quick and Measurable Learning by Content Free Diagnosis

5 Min Mentor – Quick and Measurable Learning by Content Free Diagnosis

The Antano Solar Voice  is one of the most cutting-edge blog and podcast in the world with fresh insights from validated life experience. The Solar Voice season 1 podcast has been ranked #3 in Apple iTunes News & Noteworthy. And the posts have been published in over a dozen publications including Business World, YourStory, Hindu Business Line, Economic Times and  many more. To listen to any of the past episodes for free, check out this page. And to read the past article, check out the blog page.

Leave a Reply


Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}