Paweł Nowicki
Paweł Nowicki

Reputation: 49

How to put QR code into pdf file?

how can I generate and put my QR code into a pdf file?? Theres a code that generates a pdf:

<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>"/>
</head>
<body class="pdf">
    <table class="table-label <?=$size?>">
        <tbody>
            <?php foreach ($labelFields as $key=>$value) { ?>
                <tr class="<?='row'.strtolower($key)?>">
                    <th><?=is_numeric($key)?$key+1:$key?></th><td><?=$value?></td>
                </tr>
            <?php } ?>
        </tbody>
    </table>
</body>

Code above returns a pdf which looks like that:

generated_table

I want to create a QR code and put all parameters from table to it. I've tried to do this like:

<?php
header("Content-type: image/png");
use Endroid\QrCode\QrCode;
?>

<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>"/>
</head>
<body class="pdf">
    <table class="table-label <?=$size?>">
        <tbody>
            <?php foreach ($labelFields as $key=>$value) { ?>
                <tr class="<?='row'.strtolower($key)?>">
                <?php /* klucz => wartosc; poniewaz klucz idzie od 0 zwieksz o 1 */ ?>
                    <th><?=is_numeric($key)?$key+1:$key?></th><td><?=$value?></td>
                </tr>
            <?php }
                $qrcode = new QRcode("dsfdfddsdsdsdfsdfsdfsdfs");
                //echo $qrcode->writeString();die();
            ?>
            <tr>
                <th><?='Kod QR'?></th><td><?=$qrcode->writeString()?></td>
            </tr>
        </tbody>
    </table>
</body>

Unfortunately after those changes i receive error

PHP Fatal Error – yii\base\ErrorException Maximum execution time of 30 seconds exceeded

Regards

Upvotes: 0

Views: 5508

Answers (1)

Paweł Nowicki
Paweł Nowicki

Reputation: 49

<th><?='Kod QR'?></th><td><?=$qrCode->writeDataUri()?></td>

This is solution to my problem.

Upvotes: 2

Related Questions