I have a web based application that I built using Perl, that gives the users the ability to download quotes into a PDF. Originally I had a link the user would push to get a detailed quote page as HTML, but then the users always want more.

So after trying to manually convert the HTML to PDF I went for the easy route, I used htmldoc which gets a web page and converts it to Postscript, then I use Ghostscript (ps2pdf) to make the PDF.

This worked good for me, cause I then needed to get more then one quote, so with a loop around the htmldoc and keep appending to the same output file, I got a PDf with all my needed pages.

Code Snippet I used (yea, it's not the best, but it's early code for me):

$tmp="$TMP_DIR/"."Quotes$$"."$USTATUS{USERNAME}.ps"; $htmp="$HTMP_DIR/"."Quotes$$"."$USTATUS{USERNAME}.pdf"; $tmp2=$tmp; $tmp2=~s/\.ps$/\.pdf/gi; `>$tmp`; my $ctr=0; my $tlog="$Q::all_quotes"; $tlog=~s/:/ /g; &logme('Quotes-PDF', "Getting PDF for quotes $tlog"); print "Processing quotes "; foreach $id (reverse split /:/, $Q::all_quotes) { $ctr++; print " $id "; `htmldoc -t ps --header '' --no-numbered --size letter --bodycolo +r white --left .5in --right .5in --webpage "http://localhost/cgi-bin +/po/index.cgi?session=$SESSION&user=$USTATUS{USERNAME}&qdetail=$id&no +ip=noip" >> $tmp`; } `ps2pdf $tmp $tmp2`;
Now $tmp2 is my PDF file.
Another program I use alot for making PDF's is a2ps which is Anything-To-Postscript which is alot easier for converting straight text or reports. I built a magic lp or Samba printer that takes print jobs and converts them to a PDF that then gets emailed back to the user with these methods.

ronzo


In reply to Re: Dynamically generated HTML to PDF by ronzomckelvey
in thread Dynamically generated HTML to PDF by menolly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.