PHP code example of bladepdf / php
1. Go to this page and download the library: Download bladepdf/php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bladepdf / php example snippets
use BladePDF\BladePdf;
$bladePdf = BladePdf::create($_ENV['BLADEPDF_API_KEY']);
$result = $bladePdf
->fromHtml('<h1>Invoice INV-42</h1>')
->format('A4')
->showBackground()
->render();
$result->save(__DIR__.'/invoice.pdf');
use BladePDF\Assets\AssetResolverOptions;
use BladePDF\BladePdf;
$bladePdf = BladePdf::create(
apiKey: $_ENV['BLADEPDF_API_KEY'],
assetOptions: new AssetResolverOptions(
documentRoot: __DIR__.'/public',
searchRoots: [__DIR__.'/public', __DIR__.'/storage/pdf-assets'],
localHosts: ['localhost', 'app.example.test'],
),
);
$result = $bladePdf
->fromHtml('<link rel="stylesheet" href="/css/pdf.css"><img src="/images/logo.svg#mark">')
->render();
$submission = $bladePdf
->fromTemplate('invoice.standard', ['invoice' => ['number' => 'INV-42']])
->reference('INV-42')
->storePdf()
->webhook('https://example.test/webhooks/bladepdf', 'whsec_...')
->async();
echo $submission->requestId;
use BladePDF\Webhooks\SignatureVerifier;
$valid = SignatureVerifier::isValid(
rawBody: file_get_contents('php://input'),
timestamp: $_SERVER['HTTP_BLADEPDF_TIMESTAMP'] ?? null,
signature: $_SERVER['HTTP_BLADEPDF_SIGNATURE'] ?? null,
secret: $_ENV['BLADEPDF_WEBHOOK_SECRET'],
);
bash
composer