Learn how to convert web pages and HTML documents to PDF in PHP using the Pdfcrowd API v2. The API is easy to use and the integration takes only a couple of lines of code.
Learn more about other install options (Composer, GitHub).
Authentication is needed in order to use the Pdfcrowd API. The credentials
used for accessing the API are your Pdfcrowd username and the API key.
Sign up for a Free Trial
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "example.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and store the result into the "pdf" variable $pdf = $client->convertUrl("http://www.example.com"); // at this point the "pdf" variable contains PDF raw data and // can be sent in an HTTP response, saved to a file, etc. } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create an output stream for the conversion result $output_stream = fopen("example.pdf", "wb"); // check for a file creation error if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result into the output stream $client->convertUrlToStream("http://www.example.com", $output_stream); // close the output stream fclose($output_stream); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file $client->convertFileToFile("/path/to/MyLayout.html", "MyLayout.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and store the result into the "pdf" variable $pdf = $client->convertFile("/path/to/MyLayout.html"); // at this point the "pdf" variable contains PDF raw data and // can be sent in an HTTP response, saved to a file, etc. } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create an output stream for the conversion result $output_stream = fopen("MyLayout.pdf", "wb"); // check for a file creation error if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result into the output stream $client->convertFileToStream("/path/to/MyLayout.html", $output_stream); // close the output stream fclose($output_stream); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file $client->convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and store the result into the "pdf" variable $pdf = $client->convertString("<html><body><h1>Hello World!</h1></body></html>"); // at this point the "pdf" variable contains PDF raw data and // can be sent in an HTTP response, saved to a file, etc. } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create an output stream for the conversion result $output_stream = fopen("HelloWorld.pdf", "wb"); // check for a file creation error if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result into the output stream $client->convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", $output_stream); // close the output stream fclose($output_stream); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setDebugLog(true); // run the conversion and write the result to a file $client->convertFileToFile("/path/to/MyLayout.html", "MyLayout.pdf"); // print URL to the debug log echo "Debug log url: " . $client->getDebugLogUrl() . "\n"; // print the number of available conversion credits in your account echo "Remaining credit count: " . $client->getRemainingCreditCount() . "\n"; // print the number of credits consumed by the conversion echo "Consumed credit count: " . $client->getConsumedCreditCount() . "\n"; // print the unique ID of the conversion echo "Job id: " . $client->getJobId() . "\n"; // print the total number of pages in the output document echo "Page count: " . $client->getPageCount() . "\n"; // print the size of the output in bytes echo "Output size: " . $client->getOutputSize() . "\n"; } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setPageSize("Letter"); $client->setOrientation("landscape"); $client->setNoMargins(true); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "letter_landscape.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setHeaderHeight("15mm"); $client->setFooterHeight("10mm"); $client->setHeaderHtml("<a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a>"); $client->setFooterHtml("<center><span class='pdfcrowd-page-number'></span></center>"); $client->setMarginTop("0"); $client->setMarginBottom("0"); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "header_footer.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setScaleFactor(300); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "zoom_300.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setAuthor("Pdfcrowd"); $client->setTitle("Hello World"); $client->setSubject("Demo"); $client->setKeywords("Pdfcrowd,demo"); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "with_metadata.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setPageLayout("single-page"); $client->setPageMode("full-screen"); $client->setInitialZoomType("fit-page"); $client->setOrientation("landscape"); $client->setNoMargins(true); // run the conversion and write the result to a file $client->convertUrlToFile("https://pdfcrowd.com/doc/api/", "slide_show.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setElementToConvert("#main"); // run the conversion and write the result to a file $client->convertUrlToFile("https://pdfcrowd.com/doc/api/", "html_part.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setCustomJavascript("el=document.createElement('h2'); el.textContent='Hello from Pdfcrowd API'; el.style.color='red'; el_before=document.getElementsByTagName('h1')[0]; el_before.parentNode.insertBefore(el, el_before.nextSibling)"); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "html_inject.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setViewportWidth(992); $client->setRenderingMode("viewport"); $client->setSmartScalingMode("viewport-fit"); $client->setNoMargins(true); // run the conversion and write the result to a file $client->convertUrlToFile("https://getbootstrap.com/", "bootstrap.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; require "vendor/autoload.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create ZIP archive $options = new ZipStream\Option\Archive(); $in_stream = fopen("php://memory", "rw"); $options->setOutputStream($in_stream); $zip = new ZipStream\ZipStream("stream.zip", $options); // add HTML content to the archive $zip->addFile("index.html", "<html> <head> <style> @font-face { font-family: 'OpenSans'; src: url(fonts/OpenSans.ttf) format('truetype'); } h1 { font-family: OpenSans; } </style> </head> <body> <h1>Hello World</h1> <img src='images/logo.png'> </body> </html>"); # add required local files to the archive $zip->addFileFromPath("fonts/OpenSans.ttf", "/your-path-to/fonts/OpenSans.ttf"); $zip->addFileFromPath("images/logo.png", "/your-path-to/images/logo.png"); $zip->finish(); fseek($in_stream, 0); // create an output stream for the conversion result $output_stream = fopen("HelloFromZip.pdf", "wb"); // check for a file creation error if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result into the output stream $client->convertStreamToStream($in_stream, $output_stream); // close the output stream fclose($output_stream); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setCustomJavascript("libPdfcrowd.highlightHtmlElements({backgroundColor: 'rgba(255, 191, 0, 0.1)', borderColor:null})"); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "highlight_background.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion $client->setCustomJavascript("libPdfcrowd.highlightHtmlElements({borderColor: 'orange', backgroundColor: null, padding: '4px', margin: '4px'})"); // run the conversion and write the result to a file $client->convertUrlToFile("http://www.example.com", "highlight_borders.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
The API can be easily integrated into your environment. You can have our interactive API Playground autogenerate the integration code for you:
You can also check out a complete example in our pdfcrowd-examples Github repository:
The API lets you convert a web page, a local HTML file, or a string containing HTML. The result of the conversion can be stored to a local file, to a stream object or to a variable. See the conversion input section for more details.
The best way to start with the API is to choose one of the examples and once you get it working, you can further customize the code. You can find the most common customizations in the table below.
Page size | Change the page size with setPageSize or setPageDimensions. Pass -1 to setPageHeight to get a single page PDF containing the whole document. |
Page orientation | Change the page orientation to landscape with setOrientation. |
Page margins | Adjust the page margins with setPageMargins. |
Headers and footers | Add headers and footers with setHeaderHtml and setFooterHtml. Set the height with setFooterHeight and setHeaderHeight. |
Zoom | Scale the HTML contents with setScaleFactor. |
Hide or remove elements |
You can use the following classes in your HTML code to hide or remove elements from the output:
|
Use @media print | You can switch to the print version of the page (if it exists) with setUsePrintMedia. |
Force page break |
You can force a page break with<div style="page-break-before:always"></div>
|
Avoid page break |
You can avoid a page break inside an element with the following CSSth, td, img { page-break-inside:avoid }
|
Run custom JavaScript | You can use setOnLoadJavascript or setCustomJavascript to alter the HTML contents with a custom JavaScript. In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library. |
The API enables rendering of HTML templates. The template syntax is based on the Jinja template rendering engine.
The most common constructs are:
Invoice: {{ invoice.number }}
{% for invoice in invoices %} ... {% endfor %}
{% if invoice.total > 100 %} ... {% endif %}
{{ invoice.to.first_name|capitalize }}
The supported input data formats are JSON, XML, CSV and YAML. The data can be uploaded from a file or from a string variable.
Supported template filters: capitalize, center, default, escape, first, forceescape, format, indent, join, last, length, list, lower, replace, reverse, safe, slice, sort, string, striptags, title, trim, truncate, unique, upper, wordcount, wordwrap.
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion $client->setDataString('{ "name": "World", "product": "Pdfcrowd API" }'); // run the conversion and write the result to a file $client->convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion $client->setDataString('<?xml version="1.0" encoding="UTF-8"?> <data> <name>World</name> <product>Pdfcrowd API</product> </data>'); // run the conversion and write the result to a file $client->convertStringToFile("Hello {{ data.name }} from {{ data.product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion $client->setDataString("name: World product: Pdfcrowd API"); // run the conversion and write the result to a file $client->convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
<?php require "pdfcrowd.php"; try { // create the API client instance $client = new \Pdfcrowd\HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion $client->setDataString("name,product World,Pdfcrowd API"); // run the conversion and write the result to a file $client->convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { // report the error error_log("Pdfcrowd Error: {$why}\n"); // rethrow or handle the exception throw $why; } ?>
try { // call the API } catch(\Pdfcrowd\Error $why) { // print error error_log("Pdfcrowd Error: {$why}\n"); // print just error code error_log("Pdfcrowd Error Code: {$why->getCode()}\n"); // print just error message error_log("Pdfcrowd Error Message: {$why->getMessage()}\n"); // or handle the error in your way }
libPdfcrowd.highlightHtmlElements
method call to visualize all HTML elements. See the example and helper JavaScript library documentation.
Conversion from HTML to PDF. All setter methods return HtmlToPdfClient object unless otherwise specified.
function __construct($user_name, $api_key)
user_name
Your username at Pdfcrowd.
|
api_key
Your API key.
|
function convertUrl($url)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
function convertUrlToStream($url, $out_stream)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
out_stream
The output stream that will contain the conversion output.
|
function convertUrlToFile($url, $file_path)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
file_path
The output file path.
The string must not be empty.
|
function convertFile($file)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
function convertFileToStream($file, $out_stream)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
out_stream
The output stream that will contain the conversion output.
|
function convertFileToFile($file, $file_path)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
file_path
The output file path.
The string must not be empty.
|
function convertString($text)
text
The string content to convert.
The string must not be empty.
|
function convertStringToStream($text, $out_stream)
text
The string content to convert.
The string must not be empty.
|
out_stream
The output stream that will contain the conversion output.
|
function convertStringToFile($text, $file_path)
text
The string content to convert.
The string must not be empty.
|
file_path
The output file path.
The string must not be empty.
|
function convertStream($in_stream)
in_stream
The input stream with source data.
The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2). The archive can contain HTML code and its external assets (images, style sheets, javascript). |
function convertStreamToStream($in_stream, $out_stream)
in_stream
The input stream with source data.
The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2). The archive can contain HTML code and its external assets (images, style sheets, javascript). |
out_stream
The output stream that will contain the conversion output.
|
function convertStreamToFile($in_stream, $file_path)
in_stream
The input stream with source data.
The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2). The archive can contain HTML code and its external assets (images, style sheets, javascript). |
file_path
The output file path.
The string must not be empty.
|
function setPageSize($size)
size
Allowed values:
Default: A4
|
function setPageWidth($width)
width
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
setPageWidth("300mm")
setPageWidth("9.5in")
function setPageHeight($height)
height
Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 11.7in
|
setPageHeight("350mm")
setPageHeight("15.25in")
setPageHeight("-1")
function setPageDimensions($width, $height)
width
Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
height
Set the output page height. Use -1 for a single page PDF. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 11.7in
|
setPageDimensions("300mm", "350mm")
setPageDimensions("9.5in", "15.25in")
setPageDimensions("372mm", "520pt")
function setOrientation($orientation)
orientation
Allowed values:
Default: portrait
|
function setMarginTop($top)
top
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginTop("1in")
setMarginTop("2.5cm")
function setMarginRight($right)
right
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginRight("1in")
setMarginRight("2.5cm")
function setMarginBottom($bottom)
bottom
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginBottom("1in")
setMarginBottom("2.5cm")
function setMarginLeft($left)
left
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginLeft("1in")
setMarginLeft("2.5cm")
function setNoMargins($value)
value
Set to true to disable margins.
Default: false
|
function setPageMargins($top, $right, $bottom, $left)
top
Set the output page top margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
right
Set the output page right margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
bottom
Set the output page bottom margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
left
Set the output page left margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
function setHeaderUrl($url)
url
The supported protocols are http:// and https://.
|
setHeaderUrl("http://myserver.com/header.html")
function setHeaderHtml($html)
html
The string must not be empty.
|
setHeaderHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
function setHeaderHeight($height)
height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setHeaderHeight("30mm")
setHeaderHeight("1in")
url
The supported protocols are http:// and https://.
|
setFooterUrl("http://myserver.com/header.html")
html
The string must not be empty.
|
setFooterHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setFooterHeight("30mm")
setFooterHeight("1in")
value
Set to true to disable horizontal margins for header and footer.
Default: false
|
function setPrintPageRange($pages)
pages
A comma separated list of page numbers or ranges.
|
setPrintPageRange("2")
setPrintPageRange("1,3")
setPrintPageRange("2-")
setPrintPageRange("-3")
setPrintPageRange("3,6-9")
function setExcludeHeaderOnPages($pages)
pages
List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on.
A comma separated list of page numbers.
|
setExcludeHeaderOnPages("2")
setExcludeHeaderOnPages("1,-1")
pages
List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on.
A comma separated list of page numbers.
|
setExcludeFooterOnPages("2")
setExcludeFooterOnPages("1,-1")
function setPageNumberingOffset($offset)
offset
Integer specifying page offset.
Default: 0
|
setPageNumberingOffset(1)
setPageNumberingOffset(-10)
function setContentAreaX($x)
x
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
setContentAreaX("-1in")
setContentAreaX("2.5cm")
function setContentAreaY($y)
y
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
setContentAreaY("-1in")
setContentAreaY("2.5cm")
function setContentAreaWidth($width)
width
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The width of the print area.
|
setContentAreaWidth("8in")
setContentAreaWidth("25cm")
function setContentAreaHeight($height)
height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The height of the print area.
|
setContentAreaHeight("8in")
setContentAreaHeight("25cm")
function setContentArea($x, $y, $width, $height)
x
Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
y
Set the top left Y coordinate of the content area. It is relative to the top left Y coordinate of the print area.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
width
Set the width of the content area. It should be at least 1 inch.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The width of the print area.
|
height
Set the height of the content area. It should be at least 1 inch.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The height of the print area.
|
function setCssPageRuleMode($mode)
mode
The page rule mode.
Allowed values:
Default: default
|
Methods related to HTML template rendering.
function setDataString($data_string)
data_string
The input data string.
|
function setDataFile($data_file)
data_file
The file path to a local file containing the input data.
|
function setDataFormat($data_format)
data_format
The data format.
Allowed values:
Default: auto
|
function setDataEncoding($encoding)
encoding
The data file encoding.
Default: utf-8
|
function setDataIgnoreUndefined($value)
value
Set to true to ignore undefined variables.
Default: false
|
function setDataAutoEscape($value)
value
Set to true to turn auto escaping on.
Default: false
|
function setDataTrimBlocks($value)
value
Set to true to turn auto trimming on.
Default: false
|
function setDataOptions($options)
options
Comma separated list of options.
|
setDataOptions("csv_delimiter=;")
setDataOptions("data_root=rows")
setDataOptions("xml_remove_root=1")
function setPageWatermark($watermark)
watermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
function setPageWatermarkUrl($url)
url
The supported protocols are http:// and https://.
|
setPageWatermarkUrl("http://myserver.com/watermark.pdf")
function setMultipageWatermark($watermark)
watermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
function setMultipageWatermarkUrl($url)
url
The supported protocols are http:// and https://.
|
setMultipageWatermarkUrl("http://myserver.com/watermark.pdf")
function setPageBackground($background)
background
The file path to a local background PDF file.
The file must exist and not be empty.
|
function setPageBackgroundUrl($url)
url
The supported protocols are http:// and https://.
|
setPageBackgroundUrl("http://myserver.com/background.pdf")
function setMultipageBackground($background)
background
The file path to a local background PDF file.
The file must exist and not be empty.
|
function setMultipageBackgroundUrl($url)
url
The supported protocols are http:// and https://.
|
setMultipageBackgroundUrl("http://myserver.com/background.pdf")
function setPageBackgroundColor($color)
color
The value must be in RRGGBB or RRGGBBAA hexadecimal format.
|
setPageBackgroundColor("FF0000")
setPageBackgroundColor("00ff00")
setPageBackgroundColor("00ff0080")
function setUsePrintMedia($value)
value
Set to true to use the print version of the page.
Default: false
|
function setNoBackground($value)
value
Set to true to disable the background graphics.
Default: false
|
function setDisableJavascript($value)
value
Set to true to disable JavaScript in web pages.
Default: false
|
function setDisableImageLoading($value)
value
Set to true to disable loading of images.
Default: false
|
function setDisableRemoteFonts($value)
value
Set to true disable loading remote fonts.
Default: false
|
function setLoadIframes($iframes)
iframes
Allowed values:
Default: all
|
function setBlockAds($value)
value
Set to true to block ads in web pages.
Default: false
|
function setDefaultEncoding($encoding)
encoding
The text encoding of the HTML content.
Default: auto detect
|
function setLocale($locale)
locale
The locale code according to ISO 639.
Default: en-US
|
function setHttpAuth($user_name, $password)
user_name
Set the HTTP authentication user name.
|
password
Set the HTTP authentication password.
|
function setCookies($cookies)
cookies
The cookie string.
|
setCookies("session=6d7184b3bf35;token=2710")
function setVerifySslCertificates($value)
value
Set to true to enable SSL certificate verification.
Default: false
|
function setFailOnMainUrlError($fail_on_error)
fail_on_error
Set to true to abort the conversion.
Default: false
|
function setFailOnAnyUrlError($fail_on_error)
fail_on_error
Set to true to abort the conversion.
Default: false
|
function setNoXpdfcrowdHeader($value)
value
Set to true to disable sending X-Pdfcrowd HTTP header.
Default: false
|
function setCustomJavascript($javascript)
javascript
A string containing a JavaScript code.
The string must not be empty.
|
function setOnLoadJavascript($javascript)
javascript
A string containing a JavaScript code.
The string must not be empty.
|
function setCustomHttpHeader($header)
header
A string containing the header name and value separated by a colon.
|
setCustomHttpHeader("X-My-Client-ID:k2017-12345")
function setJavascriptDelay($delay)
delay
The number of milliseconds to wait.
Must be a positive integer number or 0.
Default: 200
|
function setElementToConvert($selectors)
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
|
setElementToConvert("#main-content")
setElementToConvert(".main-content")
setElementToConvert("table")
setElementToConvert("table, #main-content")
setElementToConvert("div.user-panel.main p.article")
function setElementToConvertMode($mode)
mode
Allowed values:
Default: cut-out
|
function setWaitForElement($selectors)
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
|
setWaitForElement("#main-content")
setWaitForElement(".main-content")
setWaitForElement("table")
setWaitForElement("table, #main-content")
setWaitForElement("div.user-panel.main p.article")
function setViewportWidth($width)
width
The value must be in the range 96-65000.
Default: 1024
|
function setViewportHeight($height)
height
Must be a positive integer number.
Default: 768
|
function setViewport($width, $height)
width
Set the viewport width in pixels. The viewport is the user's visible area of the page.
The value must be in the range 96-65000.
Default: 1024
|
height
Set the viewport height in pixels. The viewport is the user's visible area of the page.
Must be a positive integer number.
Default: 768
|
function setRenderingMode($mode)
mode
The rendering mode.
Allowed values:
Default: default
|
function setSmartScalingMode($mode)
mode
The smart scaling mode.
Allowed values:
Default: default
|
function setScaleFactor($factor)
factor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
factor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
function setDisableSmartShrinking($value)
value
Set to true to disable the intelligent shrinking strategy.
Default: false
|
function setJpegQuality($quality)
quality
The percentage value.
The value must be in the range 1-100.
Default: 100
|
function setConvertImagesToJpeg($images)
images
The image category.
Allowed values:
Default: none
|
function setImageDpi($dpi)
dpi
The DPI value.
Must be a positive integer number or 0.
Default: 0
|
setImageDpi(0)
setImageDpi(72)
setImageDpi(96)
setImageDpi(150)
setImageDpi(300)
Miscellaneous values for PDF output.
function setLinearize($value)
value
Set to true to create linearized PDF.
Default: false
|
function setEncrypt($value)
value
Set to true to enable PDF encryption.
Default: false
|
function setUserPassword($password)
password
The user password.
|
function setOwnerPassword($password)
password
The owner password.
|
function setNoPrint($value)
value
Set to true to set the no-print flag in the output PDF.
Default: false
|
function setNoModify($value)
value
Set to true to set the read-only only flag in the output PDF.
Default: false
|
function setNoCopy($value)
value
Set to true to set the no-copy flag in the output PDF.
Default: false
|
function setTitle($title)
title
The title.
|
function setSubject($subject)
subject
The subject.
|
function setAuthor($author)
author
The author.
|
function setKeywords($keywords)
keywords
The string with the keywords.
|
These preferences specify how a PDF viewer should present the document. The preferences may be ignored by some PDF viewers.
function setPageLayout($layout)
layout
Allowed values:
|
function setPageMode($mode)
mode
Allowed values:
|
function setInitialZoomType($zoom_type)
zoom_type
Allowed values:
|
function setInitialPage($page)
page
Must be a positive integer number.
|
function setInitialZoom($zoom)
zoom
Must be a positive integer number.
|
function setHideToolbar($value)
value
Set to true to hide tool bars.
Default: false
|
value
Set to true to hide the menu bar.
Default: false
|
function setHideWindowUi($value)
value
Set to true to hide ui elements.
Default: false
|
function setFitWindow($value)
value
Set to true to resize the window.
Default: false
|
function setCenterWindow($value)
value
Set to true to center the window.
Default: false
|
function setDisplayTitle($value)
value
Set to true to display the title.
Default: false
|
function setRightToLeft($value)
value
Set to true to set right-to-left reading order.
Default: false
|
function setDebugLog($value)
value
Set to true to enable the debug logging.
Default: false
|
function getDebugLogUrl()
function getRemainingCreditCount()
function getConsumedCreditCount()
function getJobId()
function getPageCount()
function getOutputSize()
function getVersion()
function setTag($tag)
tag
A string with the custom tag.
|
function setHttpProxy($proxy)
proxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpProxy("myproxy.com:8080")
setHttpProxy("113.25.84.10:33333")
function setHttpsProxy($proxy)
proxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpsProxy("myproxy.com:443")
setHttpsProxy("113.25.84.10:44333")
function setClientCertificate($certificate)
certificate
The file must be in PKCS12 format.
The file must exist and not be empty.
|
function setClientCertificatePassword($password)
password
|
Expert options for fine-tuning PDF output.
function setLayoutDpi($dpi)
dpi
The DPI value.
The value must be in the range of 72-600.
Default: 300
|
function setContentsMatrix($matrix)
matrix
A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
Default: 1,0,0,0,1,0
|
setContentsMatrix("1,0,0,0,1.001,0")
setContentsMatrix("1,0,-10,0,1,-10")
function setHeaderMatrix($matrix)
matrix
A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
Default: 1,0,0,0,1,0
|
setHeaderMatrix("1,0,0,0,1.001,0")
setHeaderMatrix("1,0,-10,0,1,-10")
matrix
A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
Default: 1,0,0,0,1,0
|
setFooterMatrix("1,0,0,0,1.001,0")
setFooterMatrix("1,0,-10,0,1,-10")
function setDisablePageHeightOptimization($value)
value
Set to true to disable automatic height scale.
Default: false
|
function setMainDocumentCssAnnotation($value)
value
Set to true to add the special CSS classes.
Default: false
|
Warning
If your custom styling affects the contents area size (e.g. by using different margins, padding, border width), the resulting PDF may contain duplicit contents or some contents may be missing.
CSS styling by page number in API Playground
value
Set to true to add the special CSS classes.
Default: false
|
Different headers in API Playground
Different header for one-page and multi-page PDF in API Playground
function setConverterVersion($version)
version
The version identifier.
Allowed values:
Default: 20.10
|
function setUseHttp($value)
value
Set to true to use HTTP.
Default: false
|
Warning
Using HTTP is insecure as data sent over HTTP is not encrypted. Enable this option only if you know what you are doing.
function setUserAgent($agent)
agent
The user agent string.
Default: pdfcrowd_php_client/5.1.0 (https://pdfcrowd.com)
|
function setProxy($host, $port, $user_name, $password)
host
The proxy hostname.
|
port
The proxy port.
|
user_name
The username.
|
password
The password.
|
function setUseCurl($value)
value
Set to true to use PHP's cURL.
Default: false
|
function setRetryCount($count)
count
Number of retries wanted.
Default: 1
|