How to Convert a URL Link to a PDF Document using PHP

Cloudmersive
1 min readFeb 16, 2023

--

Much like image files, PDF files provide an excellent format for storing static information. With the PHP code examples provided in this article, you can quickly and easily implement a URL to PDF conversion service which fully renders a website’s contents within a PDF document, ensuring you can store one iteration of that website’s design for future reference.

To use this API in your app, first run this command to install the SDK:

composer require cloudmersive/cloudmersive_document_convert_api_client

Next, include the remaining code to capture your API key (get one for free here) and call the function:

<?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\UrlToPdfRequest(); // \Swagger\Client\Model\UrlToPdfRequest | URL to PDF request parameters

try {
$result = $apiInstance->convertWebUrlToPdf($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertWebApi->convertWebUrlToPdf: ', $e->getMessage(), PHP_EOL;
}
?>

After that, you’re all done — no more code required. Nice and easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet