How to HTML to PDF in PHP - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

How to HTML to PDF in PHP

This sample code demonstrates how to convert HTML to PDF in PHP using ByteScout Cloud API (low level).

Check other articles to learn how to convert HTML to PDF in Java, JavaScript and jQuery using Cloud API.

POST endoint:

https://api.pdf.co/v1/pdf/convert/from/html

Code Sample:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: api_key
Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKey('x-api-key', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Bytescout\Client\API\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer');

$api_instance = new Swagger\Client\Api\DefaultApi();
$text = ; // Text | HTML data to convert to PDF.
$name = name_example; // String | File name for the generated result.

try {
    $result = $api_instance->pdfConvertFromHtmlPost($text, $name);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling DefaultApi->pdfConvertFromHtmlPost: ', $e->getMessage(), PHP_EOL;
}
?>

Tutorials:

prev
next