How to generate PDF invoice from HTML template for HTML to PDF API in PHP and Web API

How to generate PDF invoice from HTML template for HTML to PDF API in PHP: Step By Step Tutorial

The documentation is designed to help you to implement the features on your side. HTML to PDF API in PHP can be implemented with Web API. Web API is the flexible Web API that includes full set of functions from e-signature requests to data extraction, OCR, images recognition, pdf splitting and pdf splitting. Can also generate barcodes and read barcodes from images, scans and pdf.

The SDK samples like this one below explain how to quickly make your application do HTML to PDF API in PHP with the help of Web API. This PHP sample code should be copied and pasted into your project. After doing this just compile your project and click Run. You can use these PHP sample examples in one or many applications.

Our website provides free trial version of Web API that includes source code samples to help with your PHP project.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)


<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PDF Invoice Generation Results</title> </head> <body> <?php // Get submitted form data $apiKey = $_POST["apiKey"]; // The authentication key (API Key). Get your own by registering at // HTML template $template = file_get_contents("./invoice_template.html"); // Data to fill the template $templateData = file_get_contents("./invoice_data.json"); // Prepare URL for HTML to PDF API call $url = ""; // Prepare requests params $parameters = array(); $parameters["name"] = "result.pdf"; $parameters["html"] = utf8_encode($template); $parameters["templateData"] = utf8_encode($templateData); // Create Json payload $data = json_encode($parameters); // Create request $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey, "Content-type: application/json")); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Execute request $result = curl_exec($curl); if (curl_errno($curl) == 0) { $status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($status_code == 200) { $json = json_decode($result, true); if ($json["error"] == false) { $resultFileUrl = $json["url"]; // Display link to the file with conversion results echo "<div><h2>Conversion Result:</h2><a href='" . $resultFileUrl . "' target='_blank'>" . $resultFileUrl . "</a></div>"; } else { // Display service reported error echo "<p>Error: " . $json["message"] . "</p>"; } } else { // Display request error echo "<p>Status code: " . $status_code . "</p>"; echo "<p>" . $result . "</p>"; } } else { // Display CURL error echo "Error: " . curl_error($curl); } // Cleanup curl_close($curl); ?> </body> </html>


{ "number": "1234567", "date": "April 30, 2016", "from": "Acme Inc., City, Street 3rd , +1 888 123-456,", "to": "Food Delivery Inc., New York, Some Street, 42", "lines": [{ "title": "Setting up new web-site", "quantity": 3, "price": 50 }, { "title": "Configuring mail server and mailboxes", "quantity": 5, "price": 50 }] }



Get 60 Day Free Trial

See also:


Get Your API Key

See also: