Web/HTML To PDF REST API for PHP Samples

phpSelectPdf HTML To PDF Online REST API is a professional solution that lets you create PDF from web pages and raw HTML code in your applications. The API is easy to use and the integration takes only a few lines of code. The following PHP code samples use v2 of SelectPdf Online HTML to PDF REST API.

It’s very easy to convert any URL or raw HTML string to PDF in PHP using SelectPdf HTML To PDF REST API.

Example #1 – How to convert a webpage to a PDF and stream it to the client browser as an attachment

This code converts an url to pdf in PHP using SelectPdf REST API through a GET request. The content is sent to the browser.

Example #2 – How to use PHP to convert a webpage to a PDF and save it to the disk

This code converts an url to pdf in PHP using SelectPdf REST API through a GET request. The content is saved into a file on the disk.

Example #3 – How to convert a webpage to a PDF with a POST request and save it to the disk

This code converts an url to pdf in PHP using SelectPdf REST API through a POST request. The parameters are JSON encoded. The content is saved into a file on the disk.

Example #4 – How to convert an HTML string to a PDF with a POST request and stream it to the user in the browser

This code converts a raw html string to pdf in PHP using SelectPdf REST API through a POST request. The parameters are www form encoded (application/x-www-form-urlencoded). The content is sent to the browser.

The above samples use only the 2 mandatory parameters (key and url or html) for the html to pdf conversion. For the full list of optional parameters, take a look at SelectPdf HTML To PDF REST API page. Using the API optional parameters, you can control the page size, orientation and margins in the pdf document, the document information and security, the headers and footers and a lot more.

The above PHP samples can also be found in the following GitHub repository:
https://github.com/selectpdf/selectpdf-api-php-samples