สร้าง QR Code ด้วย mPDF

wave
มานพ กองอุ่น 22 มี.ค. 2018 10:34:58 10,058

ใน mPDF เราสามารถสร้าง QR Code แทน Barcode ได้โดยเปลี่ยน type ของ barcode ดังนี้

<?php
$qr = 'data or link';
?>
<barcode code="<?=$qr?>" type="QR" size="0.3" error="M" disableborder = "1"/>

ตัวอย่าง action ใน Yii2

public function actionStickerPdf(array $selection)
    {
        $content = $this->renderPartial('_sticker', [
            'selection' => $selection,
        ]);

        $pdf = new Pdf([
            // set to use core fonts only
            'mode' => Pdf::MODE_UTF8,
            // A4 paper format
            //'format' => Pdf::FORMAT_A4,
            'format' => [25, 20],//Pdf::FORMAT_A4,
            'marginLeft' => 1,
            'marginRight' => 1,
            'marginTop' => 1,
            'marginBottom' => false,
            'marginHeader' => false,
            'marginFooter' => false,
            // portrait orientation
            'orientation' => Pdf::ORIENT_PORTRAIT,
            // stream to browser inline
            'destination' => Pdf::DEST_BROWSER,
            // your html content input
            'content' => $content,
            // format content from your own css file if needed or use the
            // enhanced bootstrap css built by Krajee for mPDF formatting
            'cssFile' => '@frontend/web/css/kv-mpdf-bootstrap.css',
            // any css to be embedded if required
            'cssInline' => 'body{font-size:11px}',
            // set mPDF properties on the fly
            'options' => ['title' => 'Sticker'],
            // call mPDF methods on the fly
            'methods' => [
                'SetHeader'=>false,
                'SetFooter'=>false,
            ]
        ]);

        // return the pdf output as per the destination setting
        return $pdf->render();
    }

ตัวอย่างไฟล์ _sticker

<?php
$qr = 'https://programmerthailand.com';
?>
<barcode code="<?=$qr?>" type="QR" size="0.3" error="M" disableborder = "1"/>

 


ความคิดเห็น

หากบทเรียนรู้มีความผิดพลาดประการใด หรือมีข้อเสนอแนะกรุณาแจ้ง contact@programmerthailand.com

เขียนบทเรียนรู้ของคุณ

รายละเอียด
  • ดู 10,058
  • รักเลย 0
  • หมวดหมู่ Yii Framework 2 (Yii2)
  • เขียนเมื่อ
  • แก้ไขเมื่อ
  • Tags mpdf qrcode
ข้อมูลผู้เขียน
มานพ กองอุ่น

มานพ กองอุ่น

เป็นสมาชิกเมื่อ: 18 ธ.ค. 2009

เนื้อหาที่เกี่ยวข้อง