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"); // create output file for conversion result $output_file = fopen("example.pdf", "wb"); // check for a file creation error if (!$output_file) throw new \Exception(error_get_last()['message']); // run the conversion and store the result into the "pdf" variable $pdf = $client->convertUrl("http://www.example.com"); // write the "pdf" variable into the output file $written = fwrite($output_file, $pdf); // check for a file write error if ($written === false) throw new \Exception(error_get_last()['message']); // close the output file fclose($output_file); } 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 output stream for 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"); // create output file for conversion result $output_file = fopen("MyLayout.pdf", "wb"); // check for a file creation error if (!$output_file) throw new \Exception(error_get_last()['message']); // run the conversion and store the result into the "pdf" variable $pdf = $client->convertFile("/path/to/MyLayout.html"); // write the "pdf" variable into the output file $written = fwrite($output_file, $pdf); // check for a file write error if ($written === false) throw new \Exception(error_get_last()['message']); // close the output file fclose($output_file); } 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 output stream for 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"); // create output file for conversion result $output_file = fopen("HelloWorld.pdf", "wb"); // check for a file creation error if (!$output_file) throw new \Exception(error_get_last()['message']); // run the conversion and store the result into the "pdf" variable $pdf = $client->convertString("<html><body><h1>Hello World!</h1></body></html>"); // write the "pdf" variable into the output file $written = fwrite($output_file, $pdf); // check for a file write error if ($written === false) throw new \Exception(error_get_last()['message']); // close the output file fclose($output_file); } 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 output stream for 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("0mm"); $client->setMarginBottom("0mm"); // 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"); $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'; 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 setPageSize($page_size)
page_size
Allowed values:
Default: A4
|
function setPageWidth($page_width)
page_width
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
setPageWidth("300mm")
setPageWidth("9.5in")
function setPageHeight($page_height)
page_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($margin_top)
margin_top
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginTop("1in")
setMarginTop("2.5cm")
function setMarginRight($margin_right)
margin_right
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginRight("1in")
setMarginRight("2.5cm")
function setMarginBottom($margin_bottom)
margin_bottom
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginBottom("1in")
setMarginBottom("2.5cm")
function setMarginLeft($margin_left)
margin_left
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginLeft("1in")
setMarginLeft("2.5cm")
function setNoMargins($no_margins)
no_margins
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($header_url)
header_url
The supported protocols are http:// and https://.
|
setHeaderUrl("http://myserver.com/header.html")
function setHeaderHtml($header_html)
header_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($header_height)
header_height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setHeaderHeight("30mm")
setHeaderHeight("1in")
footer_url
The supported protocols are http:// and https://.
|
setFooterUrl("http://myserver.com/header.html")
footer_html
The string must not be empty.
|
setFooterHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
footer_height
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setFooterHeight("30mm")
setFooterHeight("1in")
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($content_area_x)
content_area_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($content_area_y)
content_area_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($content_area_width)
content_area_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($content_area_height)
content_area_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.
|
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($data_encoding)
data_encoding
The data file encoding.
Default: utf-8
|
function setDataIgnoreUndefined($data_ignore_undefined)
data_ignore_undefined
Set to true to ignore undefined variables.
Default: false
|
function setDataAutoEscape($data_auto_escape)
data_auto_escape
Set to true to turn auto escaping on.
Default: false
|
function setDataTrimBlocks($data_trim_blocks)
data_trim_blocks
Set to true to turn auto trimming on.
Default: false
|
function setDataOptions($data_options)
data_options
Comma separated list of options.
|
setDataOptions("csv_delimiter=;")
setDataOptions("data_root=rows")
setDataOptions("xml_remove_root=1")
function setPageWatermark($page_watermark)
page_watermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
function setPageWatermarkUrl($page_watermark_url)
page_watermark_url
The supported protocols are http:// and https://.
|
setPageWatermarkUrl("http://myserver.com/watermark.pdf")
function setMultipageWatermark($multipage_watermark)
multipage_watermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
function setMultipageWatermarkUrl($multipage_watermark_url)
multipage_watermark_url
The supported protocols are http:// and https://.
|
setMultipageWatermarkUrl("http://myserver.com/watermark.pdf")
function setPageBackground($page_background)
page_background
The file path to a local background PDF file.
The file must exist and not be empty.
|
function setPageBackgroundUrl($page_background_url)
page_background_url
The supported protocols are http:// and https://.
|
setPageBackgroundUrl("http://myserver.com/background.pdf")
function setMultipageBackground($multipage_background)
multipage_background
The file path to a local background PDF file.
The file must exist and not be empty.
|
function setMultipageBackgroundUrl($multipage_background_url)
multipage_background_url
The supported protocols are http:// and https://.
|
setMultipageBackgroundUrl("http://myserver.com/background.pdf")
function setPageBackgroundColor($page_background_color)
page_background_color
The value must be in RRGGBB or RRGGBBAA hexadecimal format.
|
setPageBackgroundColor("FF0000")
setPageBackgroundColor("00ff00")
setPageBackgroundColor("00ff0080")
function setNoBackground($no_background)
no_background
Set to true to disable the background graphics.
Default: false
|
function setDisableJavascript($disable_javascript)
disable_javascript
Set to true to disable JavaScript in web pages.
Default: false
|
function setDisableImageLoading($disable_image_loading)
disable_image_loading
Set to true to disable loading of images.
Default: false
|
function setDisableRemoteFonts($disable_remote_fonts)
disable_remote_fonts
Set to true disable loading remote fonts.
Default: false
|
function setBlockAds($block_ads)
block_ads
Set to true to block ads in web pages.
Default: false
|
function setDefaultEncoding($default_encoding)
default_encoding
The text encoding of the HTML content.
Default: auto detect
|
function setHttpAuth($user_name, $password)
user_name
Set the HTTP authentication user name.
|
password
Set the HTTP authentication password.
|
function setUsePrintMedia($use_print_media)
use_print_media
Set to true to use the print version of the page.
Default: false
|
function setNoXpdfcrowdHeader($no_xpdfcrowd_header)
no_xpdfcrowd_header
Set to true to disable sending X-Pdfcrowd HTTP header.
Default: false
|
function setCookies($cookies)
cookies
The cookie string.
|
setCookies("session=6d7184b3bf35;token=2710")
function setVerifySslCertificates($verify_ssl_certificates)
verify_ssl_certificates
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 setCustomJavascript($custom_javascript)
custom_javascript
A string containing a JavaScript code.
The string must not be empty.
|
function setOnLoadJavascript($on_load_javascript)
on_load_javascript
A string containing a JavaScript code.
The string must not be empty.
|
function setCustomHttpHeader($custom_http_header)
custom_http_header
A string containing the header name and value separated by a colon.
|
setCustomHttpHeader("X-My-Client-ID:k2017-12345")
function setJavascriptDelay($javascript_delay)
javascript_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($viewport_width)
viewport_width
The value must be in the range 96-65000.
Default: 1024
|
function setViewportHeight($viewport_height)
viewport_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($rendering_mode)
rendering_mode
The rendering mode.
Allowed values:
Default: default
|
function setSmartScalingMode($smart_scaling_mode)
smart_scaling_mode
The smart scaling mode.
Allowed values:
Default: default
|
function setScaleFactor($scale_factor)
scale_factor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
header_footer_scale_factor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
function setDisableSmartShrinking($disable_smart_shrinking)
disable_smart_shrinking
Set to true to disable the intelligent shrinking strategy.
Default: false
|
function setJpegQuality($jpeg_quality)
jpeg_quality
The percentage value.
The value must be in the range 1-100.
Default: 100
|
function setConvertImagesToJpeg($convert_images_to_jpeg)
convert_images_to_jpeg
The image category.
Allowed values:
Default: none
|
function setImageDpi($image_dpi)
image_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($linearize)
linearize
Set to true to create linearized PDF.
Default: false
|
function setEncrypt($encrypt)
encrypt
Set to true to enable PDF encryption.
Default: false
|
function setUserPassword($user_password)
user_password
The user password.
|
function setOwnerPassword($owner_password)
owner_password
The owner password.
|
function setNoPrint($no_print)
no_print
Set to true to set the no-print flag in the output PDF.
Default: false
|
function setNoModify($no_modify)
no_modify
Set to true to set the read-only only flag in the output PDF.
Default: false
|
function setNoCopy($no_copy)
no_copy
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($page_layout)
page_layout
Allowed values:
|
function setPageMode($page_mode)
page_mode
Allowed values:
|
function setInitialZoomType($initial_zoom_type)
initial_zoom_type
Allowed values:
|
function setInitialPage($initial_page)
initial_page
Must be a positive integer number.
|
function setInitialZoom($initial_zoom)
initial_zoom
Must be a positive integer number.
|
function setHideToolbar($hide_toolbar)
hide_toolbar
Set to true to hide tool bars.
Default: false
|
hide_menubar
Set to true to hide the menu bar.
Default: false
|
function setHideWindowUi($hide_window_ui)
hide_window_ui
Set to true to hide ui elements.
Default: false
|
function setFitWindow($fit_window)
fit_window
Set to true to resize the window.
Default: false
|
function setCenterWindow($center_window)
center_window
Set to true to center the window.
Default: false
|
function setDisplayTitle($display_title)
display_title
Set to true to display the title.
Default: false
|
function setRightToLeft($right_to_left)
right_to_left
Set to true to set right-to-left reading order.
Default: false
|
function setDebugLog($debug_log)
debug_log
Set to true to enable the debug logging.
Default: false
|
function getDebugLogUrl()
function getRemainingCreditCount()
function getConsumedCreditCount()
function getJobId()
function getPageCount()
function getOutputSize()
function setTag($tag)
tag
A string with the custom tag.
|
function setHttpProxy($http_proxy)
http_proxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpProxy("myproxy.com:8080")
setHttpProxy("113.25.84.10:33333")
function setHttpsProxy($https_proxy)
https_proxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpsProxy("myproxy.com:443")
setHttpsProxy("113.25.84.10:44333")
function setClientCertificate($client_certificate)
client_certificate
The file must be in PKCS12 format.
The file must exist and not be empty.
|
function setClientCertificatePassword($client_certificate_password)
client_certificate_password
|
function setUseHttp($use_http)
use_http
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($user_agent)
user_agent
The user agent string.
Default: pdfcrowd_php_client/4.12.0 (http://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($use_curl)
use_curl
Set to true to use PHP's cURL.
Default: false
|
function setRetryCount($retry_count)
retry_count
Number of retries wanted.
Default: 1
|