Generate Downloadable PDF's from HTML Tables -
Generate Downloadable PDF's from HTML Tables -
can guys suggest me tools generate downloadable pdfs html tables?
if possible, compatible twitter bootstrap.
ps.: i've tried prawn, i'd know other tools.
thanks
what need know
basic perl scripting, html, perl module installation
introduction
the adobe © pdf files 1 of popular file format transferring documents. 1 of reasons displays document way printed (wysiwyg). since not require word processor browse document, lot more convenient. need reader able browse document.
perl has module allow convert html files pdf documents. done using html::htmldoc module.
installation
you need download htmldoc product easy software products. install first can proceed download html::htmldoc module cpan. 1 time download it, install typical perl modules.
generating pdf document
first thing utilize module , create instance of html::htmldoc package.
you can pass total html document bundle or tell generate pdf document html file.
sample code
#!/usr/bin/perl utilize html::htmldoc; utilize strict; #################################################### # script distributed according terms of # perl artistic license. utilize @ own risk # © 2004 philip l. yuson #################################################### $str = ' <html> <body> <p><font size=14pt><b>html pdf document</b></font></p> <p>let see how work</p> <table border=1> <tr><td>this row in table</td></tr> <tr><td>this row</td></tr> </table> <hr> copyright © 2004 philip l. yuson </body> </html>'; $html = new html::htmldoc(); # start instance $html->set_page_size('letter'); # set page size $html->set_bodyfont('arial'); # set font $html->set_left_margin(1, 'in'); # set margin $html->set_html_content($str); # contents convert $pdf = $html->generate_pdf(); # generate document $pdf->to_file('article.pdf'); # save document
save pdf.pl , run starting command line , typing this:
perl pdf.pl
this should generate pdf file similar this.
generating pdf files download on web
to generate pdf can downloaded, without saving file, can utilize same script above except need alter lastly line. however, create our illustration more interesting, set date , time on document also. script this:
#!/usr/bin/perl utilize html::htmldoc; utilize date::calc; utilize strict; #################################################### # script distributed according terms of # perl artistic license. utilize @ own risk # © 2004 philip l. yuson #################################################### @c = date::calc::today_and_now(); $str_temp; foreach (@c) { $str_temp .= sprintf("%02d:", $_); } $str = " <html> <body> <p><font size=14pt><b>html pdf document</b></font></p> <p>let see how work</p> <table border=1> <tr><td>this row in table</td></tr> <tr><td>this row</td></tr> </table> <hr> document generated: $str_temp copyright © 2004 philip l. yuson </body> </html>"; $html = new html::htmldoc(); # start instance $html->set_page_size('letter'); # set page size $html->set_bodyfont('arial'); # set font $html->set_left_margin(1, 'in'); # set margin $html->set_html_content($str); # contents convert $pdf = $html->generate_pdf(); # generate document # tell browser a pdf document print "content-type: application/pdf\n\n"; $pdf->to_string(); # send document
html table pdf twitter-bootstrap download
Comments
Post a Comment