Skip to main content

Quick Start for PHP

PHP

While wkhtmltopdf is commonly used in PHP and Puppeteer requires workarounds due to its Node.js nature, PDFBolt's PDF generation API delivers a streamlined solution for generating PDFs from HTML, URLs, and dynamic templates without needing binary installations or complex setups.

1. Get Your API Key

  • After signing up, locate your API Key in the Admin Dashboard under the API Keys section.
  • This key is essential for authorizing your requests to the PDFBolt API. Remember to keep it secure.

2. Make Your First Request

Try these examples to start making requests to the PDFBolt API and create your PDFs.

Choose your preferred endpoint and source combination:

➡️ Endpoints:

The Direct endpoint provides immediate PDF generation and returns the raw PDF file in the response.


➡️ Sources:

Convert any webpage into a PDF:

<?php

require_once 'vendor/autoload.php';
use GuzzleHttp\Client;

$jsonHeaders = '{"API-KEY":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","Content-Type":"application/json"}';
$phpHeaders = json_decode($jsonHeaders, true);

$jsonBody = '{"url":"https://example.com","format":"A4","printBackground":true}';
$phpBody = json_decode($jsonBody, true);

try {
$client = new Client();
$response = $client->post('https://api.pdfbolt.com/v1/direct', [
'headers' => $phpHeaders,
'json' => $phpBody
]);

file_put_contents('webpage.pdf', $response->getBody());
echo "PDF generated successfully\n";

} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}

?>

3. What's next?

Discover how PDFBolt can enhance your workflows. Begin with the API Endpoints and explore the Conversion Parameters to customize your setup and meet your specific needs.