Re: How can I generate a pdf from html with css?
by CountZero (Bishop) on Feb 16, 2009 at 21:27 UTC
|
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
| [reply] [Watch: Dir/Any] |
|
> 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...
UPDATE: Link (German): http://de.selfhtml.org/css/eigenschaften/printlayouts.htm
(¹) ...and of course I can also directly print to a PDF-file.
| [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html with css?
by samtregar (Abbot) on Feb 16, 2009 at 19:37 UTC
|
Not possible, at least not with the tools I've used to create PDFs. I've used htmldoc but that doesn't have much support for CSS. I've also seen PDF::Template in action, but that uses an abstract XML format, not HTML+CSS.
I think you'll need to approach building a PDF as a new format, not as a way to layout your existing HTML format.
-sam
| [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html/css?
by wazoox (Prior) on Feb 16, 2009 at 20:28 UTC
|
You probably should start from some other common documentation format such as perldoc, Robodoc, Javadoc, DocBook.... from which you can easily generate at will HTML, PDF, RTF or whatever format you wish. | [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html/css?
by boblawblah (Scribe) on Feb 17, 2009 at 01:25 UTC
|
This is something I have been looking for as well. Unfortunately, there is no such utility (that I have found) to convert HTML to PDF with CSS support. Here are the utilities that I have come across that you may be interested in:
HTMLDoc - Provides a free version (which you must compile form source or find a binary on the internet, which the provide links to) and a commercial version. Provides basic HTML support (no CSS), with some limitations (for instance - try using tables within tables to layout your pages). There is a corresponding perl module to interact with HTMLDoc.
html2ps - Converts html to postscript - not sure if supports conversion to pdf as well.
A possible alternative is to use the Gtk2::MozEmbed to render the html and print to then print to PDF. I was not able to get Gtk2::MozEmbed to work on windows (if anybody has, please contact me).
| [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html with css?
by dorward (Curate) on Feb 16, 2009 at 19:44 UTC
|
I've heard good reports about Prince XML. It isn't Perl, but can be called from it. The major disadvantage is the price.
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html with css?
by Anonymous Monk on Feb 16, 2009 at 19:36 UTC
|
This doesn't seem like a very complex thing to do, but my simple brain can't figure it out.
Because it is a very complex thing to do. What you do is install a YOURFORMAT2pdf program, and then you use it :) | [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html with css?
by ww (Archbishop) on Feb 16, 2009 at 19:34 UTC
|
Re your title, you can't use CSS to generate a .pdf from html.
;P-)
Re your actual question, check out the possibilities at CPAN or (if you're limited to windows) ppm search pdf.
Update re the first paragraph: OP's original title was "How can I generate a pdf from html with css?" | [reply] [Watch: Dir/Any] [d/l] |
Re: How can I generate a pdf from html/css?
by scorpio17 (Canon) on Feb 17, 2009 at 14:24 UTC
|
Think of the output format as the "view" part of the MVC pattern (where the page content is your data). You need one view to generate HTML (for the web page version) and another view to generate PDF (for high-quality hard-copies).
If you already have the data, and the data->html view,
all you need is the data->pdf view, which is most likely much easier to write than html->pdf.
| [reply] [Watch: Dir/Any] |
Re: How can I generate a pdf from html/css?
by Anonymous Monk on Feb 25, 2009 at 04:32 UTC
|
Thanks every one for your help. Building the PDF myself seems to be what I need to do. | [reply] [Watch: Dir/Any] |
|
see this http://artisan.karma-lab.net/node/1711 particularly url-renderer.
| [reply] [Watch: Dir/Any] |