This has been tried many times, but I have never seen a generally acceptable solution for converting a webpage to a PDF-file. It might be possible for very specific, narrowly defined and formatted webpages based upon a template where the variable data can be plugged both into an HTML and a PDF template.

The main problem is that the HTML format is geared towards very fluid and flexible rendering, all depending on the output device whereas PDF is a format for a page, where pagination, position of pictures, font size and type, ... are all most strictly defined.

If you do not care about an exact 1-to-1 rendering between the webpage and the PDF file and the HTML does not try to "fix" the lay-out but rather uses the tags as semantic and structural guides, then it might just be possible to write a parser that can translate HTML to another format (I was thinking of TeX or LaTeX) that can be rendered into a PDF-file.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

In reply to Re: Generating pdf file for and from an html file by CountZero
in thread Generating pdf file for and from an html file by RenardBleu

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.