I have a base64 text, I can convert it to pdf as I want with the following codes.
$decoded = base64_decode($r->labelData);
$file = 'label.pdf';
file_put_contents($file, $decoded);
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
But I want to use it with DOMPDF library. When I use DOMPDF the pdf page returns empty. Where am I missing?
$pdf = PDF::loadView('myPDF', ['data' => $decoded]);
return $pdf->setPaper('a4')->download('labels.pdf');
myPDF.blade.php
<body>
{{$data}}
</body>
My Answer:
$data);
file_put_contents('output.pdf', $decoded);
This code decodes the base64 text and saves it as a PDF file named 'output.pdf'.
Rate this post
4 of 5 based on 1497 votesComments