Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP QR Code scan from PDF file

Tags:

php

pdf

qr-code

I have a PDF file with a QR Code. Iuploaded the file on the server folder named "tmp" and now I need to scan and convert this QR via PHP.

I found this library:

include_once('lib/QrReader.php');
$qrcode = new QrReader('/var/tmp/qrsample.png');

$text = $qrcode->text(); //return decoded text from QR Code
print $text;

But this works only for png/jpeg files. Is there any way to scan PDF ? Is there any way to convert PDF to png only the time that I need ?

Thank you!

like image 864
L. Soprano Avatar asked Feb 12 '26 10:02

L. Soprano


1 Answers

First, transform your PDF into an image with Imagick, then use your library to decode the QRcode from it:

include_once('lib/QrReader.php');
//the PDF file
$pdf = 'mypdf.pdf';
//retrieve the first page of the PDF as image
$image = new imagick($pdf.'[0]');
//pass it to the QRreader library
$qrcode = new QrReader($image, QrReader::SOURCE_TYPE_RESOURCE);

$text = $qrcode->text(); //return decoded text from QR Code
print $text;
//clear the resources used by Imagick
$image->clear();
like image 71
Veve Avatar answered Feb 14 '26 16:02

Veve



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!