Error handling
Catch them all!
try {
$html = <<<HTML
<p>Hello,</p>
<p>This is an simple example.</p>
HTML;
$resolveUri = \Typesetsh\UriResolver::all();
$result = \Typesetsh\createPdf($html, $resolveUri);
$data = $result->asString();
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($data));
header("Content-Disposition:inline;filename=hello.pdf");
/* Merge PDF errors and resolver errors */
foreach ([...$result->issues, ...$resolveUri->errors] as $issue) {
header("X-PDF-Warning: ".$issue->getMessage());
}
echo $data;
} catch (Exception $exception) {
// Snap!
http_response_code(500);
echo "Error!";
}
Last updated