Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How can I generate a pdf from html with css?

by CountZero (Bishop)
on Feb 16, 2009 at 21:27 UTC ( [id://744209]=note: print w/replies, xml ) Need Help??


in reply to How can I generate a pdf from html/css?

I went that way but abandoned it. HTML is for a computer screen and --if well written-- will adapt to a variety of screenwidths, available fonts, font-sizes, OS-styles, browser peculiarities, ...

PDF on the other hand is really for printing things on paper and trying to do so exactly the same wherever it is printed.

HTML does not even have a concept of page-length, so how would you reliably split your HTML-"pages" into PDF-pages.

As I have to produce PDF-documents I now do so through Template Toolkit which writes me a LaTeX-file which I then feed to the pdfLaTeX program and it produces a nice 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

  • Comment on Re: How can I generate a pdf from html with css?

Replies are listed 'Best First'.
Re^2: How can I generate a pdf from html with css?
by LanX (Saint) on Feb 16, 2009 at 21:49 UTC
    > HTML does not even have a concept of page-length, so how would you reliably split your HTML-"pages" into PDF-pages.

    Well CSS2 has separate "@media" styles which you can be used for printing. This has a concept of page-length!!!

    But AFAIK that's only supported by browsers and you have to fiddle around with preset browsersettings like pagemargins and pagenumber and so on... not really a reliable approach for server programming.

    Anyway I'm using this for printing¹ some private html-pages with firefox...

    Cheers Rolf

    UPDATE: Link (German): http://de.selfhtml.org/css/eigenschaften/printlayouts.htm

    (¹) ...and of course I can also directly print to a PDF-file.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://744209]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2026-03-11 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.