By cletus


2008-12-24 08:14:20 8 Comments

I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML.

I'm now after a way of converting it to PDF. I have tried:

  • DOMPDF: it had huge problems with tables. I factored out my large nested tables and it helped (before it was just consuming up to 128M of memory then dying--thats my limit on memory in php.ini) but it makes a complete mess of tables and doesn't seem to get images. The tables were just basic stuff with some border styles to add some lines at various points;
  • HTML2PDF and HTML2PS: I actually had better luck with this. It rendered some of the images (all the images are Google Chart URLs) and the table formatting was much better but it seemed to have some complexity problem I haven't figured out yet and kept dying with unknown node_type() errors. Not sure where to go from here; and
  • Htmldoc: this seems to work fine on basic HTML but has almost no support for CSS whatsoever so you have to do everything in HTML (I didn't realize it was still 2001 in Htmldoc-land...) so it's useless to me.

I tried a Windows app called Html2Pdf Pilot that actually did a pretty decent job but I need something that at a minimum runs on Linux and ideally runs on-demand via PHP on the Webserver.

What am I missing, or how can I resolve this issue?

30 comments

@Starkers 2013-02-18 20:50:34

It's already been mentioned, but I'd just like to confirm that mpdf is the easiest, most powerful and most free html to pdf converter out there. The sky's really the limit. You can even generate pdfs of dynamic, user generated data.

For instance, a client wanted a CMS system so he could update the track list of the music he played at his club. That was no problem, but he also wanted users to be able download a .pdf of the playlist, and so this downloadable pdf had to be updated by the cms too. Thanks to mpdf, with some simple loops and interspersed variables I could do just that. Something that I thought would take me weeks literally took me minutes.

Great article that helped me get started.

@Henrik Erlandsson 2018-02-13 15:22:05

A PDF of a playlist. God help me.

@Luke Wenke 2015-05-07 10:43:28

The HTML2PDF and HTML2PS that was originally mentioned in opening post was talking about a 2009 package with this link

But there is a better HTML2PDF

It is based on TCPDF though it is partly in French.

You can have table headers or footers that repeat on the pages and have page numbers and total pages. See its examples. I have been using it for over three years and recommend it.

@degenerate 2015-06-25 17:11:15

Why isn't this on top? It works without any extra dependencies, and is good enough for most people's applications without having to spend $3800!

@SchizoDuckie 2009-01-12 08:47:28

Important: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2018. Online alternatives like PDFShift are better today at this than they were back then.


Have a look at PrinceXML.

It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But hey, your programming might not be free either, so if it saves you 10 hours of work, you're home free (since you also need to take into account that the alternative solutions will require you to setup a dedicated server with the right software)

Oh yeah, did I mention that this is the first (and probably only) HTML2PDF solution that does full ACID2 ?

PrinceXML Samples

@cletus 2009-01-12 09:19:15

Well it seems you can only download the desktop version. I'd reeally like to try the server version. But the desktop version did a superb job (equal to my final html2pdf version but virtually instantaneous). Thanks for the recommendation.

@Boris Delormas 2010-07-28 13:34:55

I've already used it for a big project. Very great tool and the support exists. Just go for it !

@acme 2010-09-15 10:03:22

PrinceXML is really awesome. Only if it was not that expensive :-(

@Joel Meador 2011-01-11 08:31:14

My company wrote a web service built around Prince. Significantly cheaper upfront costs, and usable without needing to install anything: docraptor.com

@Nate365 2011-01-15 00:30:35

I've used DocRaptor, too. Awesome way to get the benefits of Prince without having to pay for the expensive license. Congrats on a great product, Joel.

@thomallen 2012-04-18 00:17:49

Way too expensive. WKHTMLTOPDF (see other answer) is free, does the job and uses webkit which is awesome.

@A21z 2012-11-16 10:34:32

Prince or DocRaptor do a pretty bad job on non-valid inputs. wkhtmltopdf or pdfcrowd have a much better render, for cheaper

@user1914292 2013-02-17 08:13:32

there are Saas service of equal or better quality for a fraction of the price - see htm2pdf.co.uk

@David Hofmann 2014-08-29 18:33:47

I gues that the right thing to do is to make browsers produce the pdf becuase they are the only ones doing proper css/js rendering. see this question stackoverflow.com/q/25574082/39998

@chjortlund 2014-10-08 14:16:55

If you have commandline access and DON'T want to pay $3500, PhantomJS with this script: github.com/ariya/phantomjs/blob/master/examples/rasterize.js might be a solution - it's the free and easy way!

@Ronnie 2014-11-25 10:05:50

One huge benefit is that, the Prince layout engine supports all the page margins: link. But the price is really something.

@toesslab.ch 2015-02-05 19:28:34

MPdf is free, works like a charme, see answer below...

@technology101010 2018-04-08 18:40:17

really? No one mentioned FPDF here?

@SchizoDuckie 2018-04-10 11:14:47

@technology101010 no. because this question is about converting html to pdf. Not generating pdf's from scratch.

@DFSFOT 2018-06-11 17:13:43

What non-online alternative would you recommend for 2018?

@SchizoDuckie 2018-06-11 21:48:34

@DFSFOT : Definitely pdfshift. Check them out!

@DFSFOT 2018-06-12 22:13:27

@SchizoDuckie PDFShift only works with the platform right? You get the API Key and just send it over to them? I can't use that because the free plan is limited and I need to generate PDF's for a project of a client, I can't have such constraints and I can't make them pay for it either. Besides that it does look like a very robust solution, just not suitable for me. :(

@apexdodge 2018-06-26 00:39:06

Throwing api2pdf.com into the fold. It's the cheapest api out there and is a wrapper for wkhtmltopdf and headless chrome.

@Mic 2009-08-31 13:36:14

Have a look at wkhtmltopdf . It is open source, based on webkit and free.

We wrote a small tutorial here.

EDIT( 2017 ):

If it was to build something today, I wouldn't go that route anymore.
But would use http://pdfkit.org/ instead.
Probably stripping it of all its nodejs dependencies, to run in the browser.

@Koobz 2010-02-15 12:36:13

This one operates on the best premise IMO. Boostrap conversion off an existing renderer instead of writing one from scratch - not a trivial task. Furthermore, Webkit is written in C++ and therefore much faster and much less of a resource hog than PHP based implementation.

@respectTheCode 2011-05-19 15:00:40

This is great. To bad it requires the X11 client libs to be installed on the server.

@Abhi Beckert 2011-09-18 11:23:31

We have had huge problems trying to get this to render fonts properly CentOS servers. After literally weeks of messing around, it seems the only option is not to use CentOS.

@Marco Demaio 2011-10-20 15:10:53

@Mic: it's a pity that it's a binary code, you need server root access in order to install the binary. On shared/reseller hosting plans you can forget to use this WKhtmlToPDF.

@Dan Nissenbaum 2011-11-18 05:48:48

WARNING! If you use wkhtmltopdf (at least on my system, XAMPP on Windows 7 64-bit), in all cases I tried, .gif images fail to appear in the PDF file. I tried a number of workarounds suggested in various places, such as including "width" and "height", and writing the URI's according to different conventions. Nothing I tried ever caused the .gif's to appear (in particular, not even the "width" and "height" suggestion, which I tried both using inline styles and using the archaic, raw "width" and "height" HTML attributes). However, swapping the images to .jpg worked on the first try.

@Nenotlep 2012-09-18 14:06:13

I recently installed wkhtmltopdf on a Virtualbox CentOS 6 and it worked fine. You don't need root access necessarily, there are static binaries you can wget and use (tested on afromentioned CentOS). I hear lacking X11 might be an issue, but wasn't for me. It is however true that gifs don't work at all. I convert them to PNGs on the fly and generally try to prefer other formats.

@Fitrah M 2013-02-21 03:55:38

WKHTMLTOPDF is very good. Before I use it, I did my work converting many html to pdf in one day. But with WKHTMLTPDF, now I do my work converting them in just 15 minutes.

@saada 2013-11-17 21:33:55

This abstraction is pretty nice though mikehaertl.github.io/phpwkhtmltopdf

@Aditya P Bhatt 2013-11-28 10:50:10

where it stores the converted pdf file in windows env for ex. WAMP? When I run command via command tool, it shows progressing and completing however I could not find the output file in my computer? lol.. pls help

@Daniel Andersson 2014-04-07 07:24:56

@AbhiBeckert: I had the same issue with Debian and Fedora, and years later, it seems to have been pinpointed and solved: github.com/wkhtmltopdf/wkhtmltopdf/issues/45 .

@eagle779 2014-04-09 01:08:11

The commercial services were all too expensive for us so we implemented WKHTMLTOPDF as a free cloud service html2pdfrocket.com for anyone to use, and then used it ourselves for our clients. We did it that way so our clients didn't have to installed exe's on their servers etc and works cross platform. I definitely rate WKHTMLTOPDF if you are building your own service.

@barto 2014-09-12 12:36:50

Very nice indeed. I'm just wondering, is it possible not to have selectable text in the output pdf? (I'm on a Win7 Home.) Recognisable text makes the pdf fragile when it comes to printing.

@rockdaboot 2016-05-02 15:10:02

Just opened a Github repo to show how to generate an PDF DinA4 invoice using HTML5+CSS+PHP+wkhtmltopdf. Easily adjustable. github.com/rockdaboot/invoice-html5-to-pdf

@David López 2018-03-10 14:13:30

wkhtmltopdf is pretty nice. I just built an HTTP API with PHP that allows to pass an URL of a webpage and converts it from HTML to PDF using wkhtmltopdf: github.com/Dellos7/dhtml2pdf

@lubosdz 2018-06-12 09:59:07

Installation on CentOS 6/7 is easy yum --enablerepo=epel-testing install wkhtmltopdf Xvfb. Please note that wkhtml emulates browser so if the page loads google fonts, then access to the internet must be enabled. Also when using via php-fpm then environment variable with path to executable binary must be set e.g. in /etc/php-fpm.d/www.conf set env[PATH] = "/usr/bin" since fpm child process by default cleans parent's environment.

@Darryl Hein 2009-02-21 20:50:48

Checkout TCPDF. It has some HTML to PDF functionality that might be enough for what you need. It's also free!

@Hendra Uzia 2011-07-15 08:17:19

it's support is for rendering html is rather limited, you might want to read this: tcpdf.org/doc/classTCPDF.html#ac3fdf25fcd36f1dce04f92187c621‌​407

@KBK 2015-11-16 10:38:19

but css style not working

@T.Todua 2013-11-28 14:52:06

1) use MPDF !

a) extract in yourfolder

b) create file.php in yourfolder and insert such code:

<?php
include('../mpdf.php');
$mpdf=new mPDF();
$mpdf->WriteHTML('<p style="color:red;">Hallo World<br/>Fisrt sentencee</p>');
$mpdf->Output();   exit;
 ?>

c) open file.php from your browser




2) Use pdfToHtml !

1) extract pdftohtml.exe to your root folder:

2) inside that folder, in anyfile.php file, put this code (assuming, there is a source example.pdf too):

<?php
$source="example.pdf";
$output_fold="FinalFolder";

    if (!file_exists($output_fold)) { mkdir($output_fold, 0777, true);}
$result= passthru("pdftohtml $source $output_fold/new_filename",$log);
//var_dump($result); var_dump($log);
?>

3) enter FinalFolder, and there will be the converted files (as many pages, as the source PDF had..)

@user676505 2016-12-05 15:20:10

I would try GrabzIt their API supports CSS, JavaScript and most other resource types. It just needs to be referenced with absolute URL's, or made inline and included in the HTML that is sent to the service. Try it here: grabz.it/html-to-pdf-image-api.aspx

@chatoxz 2017-06-26 12:48:02

GrabzIt is not free

@Karthick 2010-03-26 11:11:18

Why don’t you try mPDF version 2.0? I used it for creating PDF a document. It works fine.

Meanwhile mPDF is at version 5.7 and it is actively maintained, in contrast to HTML2PS/HTML2PDF

But keep in mind, that the documentation can really be hard to handle. For example, take a look at this page: https://mpdf.github.io/.

Very basic tasks around html to pdf, can be done with this library, but more complex tasks will take some time reading and "understanding" the documentation.

@conualfy 2013-01-16 19:55:48

It is true, mpdf really works and it is fast, it creates the pdf file on the fly.

@Smith Smithy 2013-09-15 20:55:56

I tried a bunch of the suggested ones here. So far, this one was uploaded and worked out of the box without any hassle and the docs are truly amazing compared to the rest. Instructions for use are clearly written.

@Stefan 2014-08-09 21:45:02

mPDF giving me some serious hassles when POSTing html tags with image background or tags from database: mPDF error: IMAGE Error (http://www.example.com/folder/image.jpg): Error parsing image file - image type not recognised, and not supported by GD imagecreate

@toesslab.ch 2015-02-05 19:26:56

Version 6.0 works just as expected: include it (or in a framework, load it) instantiate, fill with your stuff, output it a way or another... That's it!

@Qullbrune 2015-03-13 10:55:49

Well MPDF is working well, true! But the code and documentation are inconsistent - it´s really hard to accomplish a more complex task e.g. creating a letter regarding the din-norm.

@Joao 2016-02-13 19:08:21

Claims that it is a lot slower than html2fpdf. But for basic content, I thought it was plenty fast (invoices, reports, etc). The huge plus for mPDF is there are hardly any PHP extension requirements (works out of the box on shared hosting)

@Nitin 2017-11-04 21:04:42

The licensing has also improved for the better. Mpdf is the way to go to create pdf from html and css.

@Henrik Erlandsson 2018-02-13 15:23:35

I don't recommend 5.7 for the CSS part of the question. Don't expect much styling of your HTML at all.

@Arachnid 2010-08-24 19:01:54

Darryl Hein's mention above of TCPDF is likely a great idea. Nicola Asuni's code is pretty handy and powerful. The only killer is if you ever plan on merging PDF files with your generated PDF it doesn't have those features. You would have to create the PDF and then merge it using something like PDFTK by Sid Steward (www.pdflabs.com/tools/pdftk-the-pdf-toolkit/).

@Giorgio Bozio 2016-06-22 14:22:52

I developed a public API to build PDF files from web pages. It has a nice PHP client class that makes it super easy to use. It uses wkhtmltopdf to render the PDF in the cloud.

No need for anything special in the HTML. No need for absolute URLS in images/css/js links. Works on localhost (dev machine) too.

Currently the service has endpoints in 4 Azure regions: US East, US West, EU North, Southeast Asia.

It's fast since it uses a proprietary protocol to send the web page contents to the API for conversion to PDF.

It's reliable because all endpoints are load balanced.

Free account available for testing or low usage. Details on the web site:

https://rotativahq.com

@Frank 2016-02-11 17:51:41

In terms of cost, using a web-service (API) may in many cases be the more sensible approach. Plus, by outsourcing this process you unburden your own infrastructure/backend and - provided you are using a reputable service - ensure compatibility with adjusting web standards, uptime, short processing times and quick content delivery.

I've done some research on most of the web services currently on the market, please find below the APIs that I feel are worth mentioning on this thread, in an order based on price/value ratio. All of them are offering pre-composed PHP classes and packages.

  1. pdflayer.com - Cost: $ - Quality: ☆☆☆☆
  2. docraptor.com - Cost: $$$ - Quality: ☆☆☆☆☆
  3. pdfcrowd.com - Cost: $$ - Quality: ☆☆☆

Quality:

Having the high-quality engine PrinceXML as a backbone, DocRaptor clearly offers the best PDF quality, returning highly polished and well converted PDF documents. However, the pdflayer API service gets pretty close here. Pdfcrowd does not necessarily score with quality, but with processing speed.

Cost:

pdflayer.com - As indicated above, the most cost-effective option here is pdflayer.com, offering an entirely free subscription plan for 100 monthly PDFs and premium subscriptions ranging between $9.99-$119.99. The price for 10,000 monthly PDF documents is $39.99.

docraptor.com - Offering a 7-Day Free Trial period. Premium subscription plans range from $15-$2250. The price for 10,000 monthly PDF documents is ~ $300.00.

pdfcrowd.com - Offering 100 PDFs once for free. Premium subscription plans range from $9-$89. The price for 10,000 monthly PDF documents is ~ $49.00.

I've used all three of them and this text is supposed to help anyone decide without having to pay for all of them. This text has not been written to endorse any one product and I have no affiliation with any of the products.

@freewill 2016-02-25 13:14:36

Thanks for the sharings. I was investigating all options whole day and had concentrated more on free libs or buying the lib. Your answer help me to thnik again. I thnik for small business it is the cost-effective way and easiest way to go with the web services. For pdflayer.com; less than $100/year it takes 20 or 30 years to break even, yet I dont thnik we will leave in the same world 20 years later :)

@apexdodge 2018-06-26 01:08:07

api2pdf.com is cheaper than all of those. ~10,000 PDFs for $2

@cletus 2009-01-12 03:51:12

After some investigation and general hair-pulling the solution seems to be HTML2PDF. DOMPDF did a terrible job with tables, borders and even moderately complex layout and htmldoc seems reasonably robust but is almost completely CSS-ignorant and I don't want to go back to doing HTML layout without CSS just for that program.

HTML2PDF looked the most promising but I kept having this weird error about null reference arguments to node_type. I finally found the solution to this. Basically, PHP 5.1.x worked fine with regex replaces (preg_replace_*) on strings of any size. PHP 5.2.1 introduced a php.ini config directive called pcre.backtrack_limit. What this config parameter does is limits the string length for which matching is done. Why this was introduced I don't know. The default value was chosen as 100,000. Why such a low value? Again, no idea.

A bug was raised against PHP 5.2.1 for this, which is still open almost two years later.

What's horrifying about this is that when the limit is exceeded, the replace just silently fails. At least if an error had been raised and logged you'd have some indication of what happened, why and what to change to fix it. But no.

So I have a 70k HTML file to turn into PDF. It requires the following php.ini settings:

  • pcre.backtrack_limit = 2000000; # probably more than I need but that's OK
  • memory_limit = 1024M; # yes, one gigabyte; and
  • max_execution_time = 600; # yes, 10 minutes.

Now the astute reader may have noticed that my HTML file is smaller than 100k. The only reason I can guess as to why I hit this problem is that html2pdf does a conversion into xhtml as part of the process. Perhaps that took me over (although nearly 50% bloat seems odd). Whatever the case, the above worked.

Now, html2pdf is a resource hog. My 70k file takes approximately 5 minutes and at least 500-600M of RAM to create a 35 page PDF file. Not quick enough (by far) for a real-time download unfortunately and the memory usage puts the memory usage ratio in the order of 1000-to-1 (600M of RAM for a 70k file), which is utterly ridiculous.

Unfortunately, that's the best I've come up with.

@ripa 2013-06-28 11:27:14

@cletus can you plz tell me about the stable version of HTML2PDF. The above link example has deprecated

@Luke Wenke 2016-08-29 05:55:28

For the latest version see github.com/spipu/html2pdf

@MickLH 2016-11-20 20:31:28

Grim typo becomes more grim: Memory usage ratio is on the order of 10,000-to-1 lol

@Oren 2010-11-13 00:48:16

I suggest DocRaptor (which uses PrinceXML as the "engine")

@Vilhelm 2011-06-09 09:55:34

Unfortunately impossible to use if you want to generate large PDF-files with a lot of images. I think there is a 60 second timelimit on requests and if Docraptor needs to download a lot of files this will be exceeded, and no file will be made.

@illbzo1 2011-12-28 21:08:02

This issue Vilhelm mentioned has been fixed.

@chjortlund 2014-10-08 14:14:59

If you have access to the command line it's possible to use PhantomJS to create the PDF from an URL (remote or local).

It works really well, and is a free solution.

Take a look at this example script made for this exact problem.

@Mihai Crăiță 2018-04-07 07:26:15

but you might have some problems with the fonts (webfonts)

@user1914292 2014-06-02 17:59:32

Although there are many solutions offered already, I recommend the following two:

  1. HTM2PDF - offers an API to convert HTML to PDF and also has a PHP SDK, which makes it very easy to implement in PHP; It offers a choice of server locations in Europe, Asia and the USA
  2. PDFmyURL - offers an API that does URL and HTML to PDF as well, with roughly the same functionality as HTM2PDF, but works on a load balanced landscape and has been around a little longer

The thing that's different about these two APIs from all the previously mentioned solutions, is that - besides converting HTML to PDF with CSS and JavaScript - it also offers PDF rights management, watermarking and encryption. Therefore it's an all-in-one solution for those who want to hit the ground running.

Disclaimer: I work for Kaiomi, a company that operates both of these websites.

@Robin van Baalen 2014-07-31 17:31:18

I wouldn't want to rely on a service when it's up for sale. Given the fact that it was unsold in that auction, I can only assume it will be sold in the near future?

@user1914292 2014-08-03 18:21:59

actually my company acquired it some time after the auction....

@Robin van Baalen 2014-08-05 13:34:26

In that case, I suppose there is nothing to worry about.

@Superdrac 2014-04-23 14:40:16

Web API

If there is people who always search for this kind of stuff, there is a free website which allow you to convert html code & pages to pdf. There is also a (very small) api which allow you to get pdf file from url.

Check it here

@Arni J 2011-08-10 13:16:42

Try grabbing the latest nightly dompdf build - I was using an older version that was a terrible resource hog and took forever to render my pdf. After grabbing a nightly from here.

It only took a few seconds to generate the PDF - AND it was just as nicely rendered as with PrinceXML / Docraptor. Seems like they've seriously optimized the dompdf code since I last used it!

@Rituparna sonowal 2016-08-06 23:04:24

dompdf is really a great option. I have used two times and it's very easy. I will recommend to try dompdf. Here is the link for official github repo: github.com/dompdf/dompdf

@Ivan Kurmanov 2012-10-03 17:33:49

not PHP, but a Java library, which does the thing:

Flying Saucer takes XML or XHTML and applies CSS 2.1-compliant stylesheets to it, in order to render to PDF

It is usable from PHP via system() or a similar call. Although it requires XML well-formedness of the input.

@lubosdz 2013-12-08 11:09:22

TCPDF works fine, no dependencies, is free and constantly bugfixed. It has reasonable speed if supplied HTML/CSS contents is well formated. I normally generate from 50 - 300 kB of HTML input (including CSS) and get PDF output within 1-3 secs with 10 - 15 PDF pages.

I strongly recommend using tidy library as HTML pretty formatter before sending anything to TCPDF.

@Oliver Schafeld 2013-08-29 15:06:44

Does the HTML to PDF conversion really need to occur server-side using PHP?

I just came across jsPDF, a client-side solution using HTML5/JavaScript. The MIT-licensed code is on GitHub, too.

@YXN 2017-05-12 05:07:14

for me, the library is very limited

@Filip Dupanović 2009-01-21 23:32:29

Just to bump the thread, I've tried DOMPDF and it worked perfectly. I've used DIV and other block level elements to position everything, kept it strictly CSS 2.1 and it played veru nicely.

@trullallero 2013-05-22 06:47:40

I've tried a lot of different libraries for PHP. All the listed I've tried. In my opinion TCPDF library is the best compromise performance/usability. It's very simply to install and use, also good performance in small medium application. If you need high performance and very big PDF document, use Zend_PDF module, but get ready to coding hard!

@criss_ae 2013-05-17 12:38:12

I recommend TCPDF or DOMPDF, is that order

@datasn.io 2008-12-27 06:17:59

Well if you want to find a perfect XHTML+CSS to PDF converter library, forget it. It's far from possible. Because it's just like finding a perfect browser (XHTML+CSS rendering engine). Do we have one? IE or FF?

I have had some success with DOMPDF. The thing is that you have to modify your HTML+CSS code to go with the way the library is meant to work. Other than that, I have pretty good results.

See below:

Original HTML

Converting HTML to PDF

@Koen. 2012-02-20 15:19:17

This question is pretty old already, but haven't seen anyone mentioning CutyCapt so I will :)

CutyCapt

CutyCapt is a small cross-platform command-line utility to capture WebKit's rendering of a web page into a variety of vector and bitmap formats, including SVG, PDF, PS, PNG, JPEG, TIFF, GIF, and BMP

@Paulo Coghi 2011-11-21 20:23:29

Good news! Snappy!!

Snappy is a very easy open source PHP5 library, allowing thumbnail, snapshot or PDF generation from a url or a html page. And... it uses the excellent webkit-based wkhtmltopdf

Enjoy! ^_^

@David López 2018-03-10 14:14:55

I built an HTTP API that uses Snappy (based on wkhtmltopdf). You can pass in an URL and converts the webpage from HTML to PDF: github.com/Dellos7/dhtml2pdf

@Strae 2009-05-12 21:02:00

I dont think a php class will be the best for render an xHtml page with css.

What happen when a new css rule come out? (soon css 3.0...)

The best way to render an html page is, obvisiuly, a browser. Firefox 3.0 can natively 'print' in pdf format, torisugary developed an extension (command line print) to use it. Here you'll find it.

Anyway, there are still many problmes runninr firefox just as a pdf converter...

At the moment, i think that wkhtmltopdf is the best (that is the one used by the safari browser), fast, quick, awesome. Yes, opensource as well... Give it a look

@Luke Wenke 2016-08-29 06:12:29

PHP is useful if you want to output some type of official documentation such as a receipt for a user and you can use CSS to make it look nice.

@ 2009-02-21 20:21:17

I am using fpdf to produce pdf files using php. It's working well for me so far to produce simple outputs.

@yoavf 2008-12-24 09:46:11

There's a tutorial on Zend's devzone on generating pdf from php (part 1, part 2) without any external libraries. I never implemented this sort of solution, but since it's all php, you might find it more flexible to implement and debug.

@charles.cc.hsu 2016-02-29 06:06:35

@PhiLho 2008-12-24 09:16:29

Perhaps you might try and use Tidy before handing the file to the converter. If one of the renderer chokes on some HTML problem (like unclosed tag), it might help it.

@cletus 2008-12-24 09:36:31

Yes a valid point but I've thought of this already. There are no unmatched nor nonstandard tags in my HTML.

@Stephan Eggermont 2008-12-24 09:09:27

Fine rendering doesn't mean anything. Does it validate?

All browsers do the most they can to just show something on the screen, no matter how bad the input. And of course they do not do the same thing. If you want the same rendering as FireFox, you could use its rendering engine. There are pdf generators for it. It is an awful lot of work, though.

@cletus 2008-12-24 12:16:57

Yes it validates.

Related Questions

Sponsored Content

37 Answered Questions

[SOLVED] How do I vertically center text with CSS?

9 Answered Questions

[SOLVED] Why does HTML think “chucknorris” is a color?

20 Answered Questions

[SOLVED] Recommended way to embed PDF in HTML?

  • 2008-11-14 23:55:13
  • Daniel Silveira
  • 1173181 View
  • 1007 Score
  • 20 Answer
  • Tags:   html pdf

27 Answered Questions

[SOLVED] How do I give text or an image a transparent background using CSS?

  • 2009-04-30 09:00:02
  • Stijn Sanders
  • 1491664 View
  • 2043 Score
  • 27 Answer
  • Tags:   html css opacity

18 Answered Questions

[SOLVED] Is it possible to apply CSS to half of a character?

26 Answered Questions

[SOLVED] Is there a CSS parent selector?

  • 2009-06-18 19:59:36
  • jcuenod
  • 1509887 View
  • 2603 Score
  • 26 Answer
  • Tags:   css css-selectors

31 Answered Questions

[SOLVED] Change an HTML5 input's placeholder color with CSS

18 Answered Questions

[SOLVED] Reference — What does this symbol mean in PHP?

26 Answered Questions

[SOLVED] Set cellpadding and cellspacing in CSS?

2 Answered Questions

[SOLVED] how to convert HTML + CSS to PDF with PHP?

  • 2013-06-27 15:10:19
  • Emil Morris
  • 10195 View
  • -1 Score
  • 2 Answer
  • Tags:   php html pdf

Sponsored Content