Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple qrcode to generate in DOMPDF

Hi i cant generate simpleqrcode in dompdf

Here is my blade.php

<img src="data:image/png;base64, {!! base64_encode(QrCode::format('svg')->size(200)->errorCorrection('H')->generate('string')) !!}">

in my controller

 public function printpdf($isbn)
    {
       $data = [
          'isbn' => $isbn
            ];

        $pdf = PDF::loadView('main.inventory.view_pdf ', $data);  
        return $pdf->stream($isbn.'.pdf');
    }

i tried this image and successfully render

<img src="{{ public_path('/uploads/image/1578635297.jpg')}}" style="width:30%;height:50%;">

Dont know why i cant generate qrcode to dompdf but when i generate in other blade its working but not in dompdf

like image 407
Harvz Mendoza Avatar asked Dec 14 '25 04:12

Harvz Mendoza


1 Answers

I got mine working by initializing the base64_encode(QrCode::format('svg')->size(200)->errorCorrection('H')->generate('string')) in a variable within a controller, and passing it to the view.

Controller:

public function foobar() {
   $qrcode = base64_encode(QrCode::format('svg')->size(200)->errorCorrection('H')->generate('string'));
   $pdf = PDF::loadView('main.inventory.view_pdf', compact('qrcode'));
   return $pdf->stream();
}

View:

<img src="data:image/png;base64, {!! $qrcode !!}">

Used laravel-snappy instead of laravel-dompdf. https://github.com/barryvdh/laravel-snappy

If you're still unable to generate a pdf file, then temporarily change the read-write permissions of the folder with chmod -R 777 <folder_path>.

like image 103
seanquijote Avatar answered Dec 16 '25 23:12

seanquijote



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!