How to convert HTML to PDF in PHP
1 min readJul 31, 2019
Here is a very simple way to handle conversion of HTML to PDF using our API. Let’s begin with adding the following reference:
"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",
}
Now, we call convertWebHtmlToPdf as follows, with our desired URL as the input:
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');$apiInstance = new Swagger\Client\Api\ConvertWebApi(
new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\HtmlToPdfRequest(); // \Swagger\Client\Model\HtmlToPdfRequest | HTML to PDF request parameterstry {
$result = $apiInstance->convertWebHtmlToPdf($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertWebApi->convertWebHtmlToPdf: ', $e->getMessage(), PHP_EOL;
}
?>
Done! Almost too easy, right? Our Convert API can be used for all sorts of other useful file conversions and alterations, so be sure to look at our documentation for the full list.