ByteScout Cloud API Server - HTML To PDF API - PHP - Generate PDF Invoice From HTML Template - ByteScout

ByteScout Cloud API Server – HTML To PDF API – PHP – Generate PDF Invoice From HTML Template

  • Home
  • /
  • Articles
  • /
  • ByteScout Cloud API Server – HTML To PDF API – PHP – Generate PDF Invoice From HTML Template

How to generate PDF invoice from HTML template for HTML to PDF API in PHP with ByteScout Cloud API Server

Step By Step Instructions on how to generate PDF invoice from HTML template for HTML to PDF API in PHP

The sample source codes on this page will show you how to create HTML to PDF API in PHP. ByteScout Cloud API Server was designed to assist HTML to PDF API in PHP. ByteScout Cloud API Server is API server that is ready to use and can be installed and deployed in less than 30 minutes on your own Windows server or server in a cloud. It can save data and files on your local server-based file storage or in Amazon AWS S3 storage. Data is processed solely on the API server and is powered by ByteScout engine, no cloud services or Internet connection is required for data processing..

The SDK samples displayed below below explain how to quickly make your application do HTML to PDF API in PHP with the help of ByteScout Cloud API Server. Open your PHP project and simply copy & paste the code and then run your app! Further improvement of the code will make it more robust.

Free! Free! Free! ByteScout free trial version is available for FREE download from our website. Programming tutorials along with source code samples are assembled.

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

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

generate-invoice.php
      
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PDF Invoice Generation Results</title> </head> <body> <?php // Please NOTE: In this sample we're assuming Cloud Api Server is hosted at "https://localhost". // If it's not then please replace this with with your hosting url. // Get submitted form data // 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 = "https://localhost/pdf/convert/from/html?name=result.pdf"; // Create HTML to PDF options $data = json_encode(array( "html" => utf8_encode($template), "templateData" => utf8_encode($templateData) )); // Create request $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, array("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>

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next