Download php html to pdf class

HTML to PDF API for PHP

This is the documentation of the PHP client library for the Pdfcrowd HTML to PDF API. Here are some sample PDFs generated by the API:

Installation

Integration with your application is a matter of a few minutes:

  1. Sign up and obtain your username and API key.
  2. Download the client library: pdfcrowd-4.2.0-php.zip
  3. Unpack the downloaded .zip file and copy pdfcrowd.php to your source tree.

You can also check out the source on Github: pdfcrowd-php

The library requires PHP 5.0 and higher and it depends on cURL.

Getting Started

This code converts a web page and sends the generated PDF as an HTTP response (in the following examples, do not forget to replace "username" and "apikey" with your username and API key)

You can also convert raw HTML code, just use the convertHtml() method instead of convertURI() :

The API lets you also convert a local HTML file:

You can save the generated PDF to a file:

More examples can be found in this Convert HTML To PDF in PHP tutorial.

Error Handling

API Reference

class Pdfcrowd (view source)

Provides access to the Pdfcrowd API from your PHP applications.

Constructor

Conversion

outstream is a handle created using fopen() . If outstream is not provided then the return value is a string containing the created PDF.

Page Setup

Header and Footer

Example: "1,-1" will not print the header and footer on the first and the last page.

Example: if set to "1" then the page numbering will start with 1 on the second page.

HTML options

PDF options

Miscellaneous

class PdfcrowdException

Derived from Exception . It is thrown when an error occurs. Use getMessage() method to get the error message. getCode() returns the HTTP status code.

Page dimensions and margins can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). If no units are specified, points are assumed. Examples: "210mm" , "8.5in" .