Converting HTML to PDF (not PDF to HTML) using PHP [closed]

Solution 1:

Regarding wkhtmltopdf:

  • This thing works blazingly fast and it can also handle all kinds of HTML/CSS you throw at it, so when you need speed, you should seriosly consider it. We switch to it recently in our company and our PDF serving got enourmous speed-boost.

  • At least under Linux it needs XOrg libraries to be installed - servers usually don't have them, so that might be your problem.

Solution 2:

Try this:

  • tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples
  • fpdf.org
  • http://code.google.com/p/wkhtmltopdf/

Solution 3:

Have you tried Prince?

Solution 4:

There are many solution to convert HTML to PDF, I can suggest you the one by https://grabz.it.

The have a flexible PHP API which can be used by cronjobs or directly from PHP web page.

If you want to try it, at first you should get an app key + secret for authorization and the development free SDK

Here is an example of a basic implementation.

//First init
include("GrabzItClient.class.php");

// Create the GrabzItClient class
// Replace "APPLICATION KEY", "APPLICATION SECRET" values for your account!
$grabzIt = new GrabzItClient("Application Key", "Application Secret");

// To take a PDF screenshot
$grabzIt->URLToPDF("http://www.google.com");

// To save in case public callback handler is available
$grabzIt->Save("http://www.example.com/handler.php");   
// OR To save in case public callback handler is not available,
// it's a synchonous method can be usedthe will force your application to wait 
// while the screenshot is created
$filepath = "images/result.jpg";
$grabzIt->SaveTo($filepath);    

It's possible to get other kinds of screenshots such as image screenshot and etc.