Want to generate PDF invoices for your client? Simply create a HTML/CSS version of the invoice, and use the PDFace HTML to PDF API to convert this HTML document into a PDF file.
PDF-ace.com API is very easy to use. All you need to do is "POST" request parameters to a URL and get back PDF in response. See below for more details.
"POST" your requests to the below URL. Make sure to always use HTTPS. Non-SSL requests will be rejected.
https://apibox1.pdface.net/index.php/v1/api
Each API call needs to include a "hash" POST parameter. To generate a hash, you will need:
<?php
$api_key = "YOUR_API_KEY";
$hash_key = "YOUR_API_HASH_KEY";
$hash = sha1($api_key . $hash_key);
?>
Follow the below steps to generate new API key/secret:
<?php
$api_key = "YOUR_API_KEY";
$hash_key = "YOUR_API_HASH_KEY";
$hash = sha1($api_key . $hash_key);
$params = [
"key" => $api_key,
"hash" => $hash,
"type" => "html",
"data" => "<h1>Hello World!</h1>",
"title" => "PDF-ace.com HTML to PDF API Example",
"orientation" => "Landscape"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://apibox1.pdface.net/index.php/v1/api");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$pdf_response = curl_exec($ch);
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error_str = curl_error($ch);
curl_close($ch);
if ($response_code == 200) {
//Save PDF response to a file
file_put_contents("hello_world.pdf", $pdf_response);
}else {
echo "Error: $pdf_response";
}
?>
List of all request parameters available to the API. You can use these request parameters to control the PDF document generated by the API.
Parameter | Type | Mandatory | Description |
---|---|---|---|
key | String | Yes | Your API Key. Login to your account to manage and generate new API keys. |
hash | String | Yes | Security hash to authenticate API calls. See "Authenticate API Calls" below. |
type | String | Yes | For now, set this to "html". |
data | String | Yes |
The HTML code that you want to convert to PDF. Example:
|
orientation | String | No | Page orientation. Set to Landscape or Portrait (default Portrait). |
page-size | String | No | Page size. Example: A4, A5, B0, B1, Executive, Letter etc. |
title | String | No | Title of the generated PDF file. |
image-quality | Integer | No | Image quality to use when JPEG compressing images (default 94). |
margin-top | Integer | No | Page top margin. Examples: 10mm, 1cm, 20pixel. |
margin-bottom | Integer | No | Page bottom margin. Examples: 10mm, 1cm, 20pixel. |
margin-left | Integer | No | Page left margin. Examples: 10mm, 1cm, 20pixel. |
margin-right | Integer | No | Page right margin. Examples: 10mm, 1cm, 20pixel. |
no-outline | Integer (0/1) | No | By default the API will put an outline into the PDF file. Set this to 1 to prevent this. |
grayscale | Integer (0/1) | No | Set to 1 to generate PDF in grayscale. |
disable-external-links | Integer (0/1) | No | Set to 1 to stop API from rendering links to remote webpages. |
no-images | Integer (0/1) | No | Set to 1 to exclude images from the generated PDF file. |
print-media-type | Integer (0/1) | No | Set to 1 use print media-type instead of screen. |