mpdf / qrcode

QR code generating library with HTML/PNG/mPDF output possibilities
GNU Lesser General Public License v3.0
45 stars 13 forks source link

QR Code stripping multiple consecutive spaces from the entered code #13

Closed ianhattti closed 1 year ago

ianhattti commented 1 year ago

I found this bug

Attempting to create a QR code with the value ETEX14 0001 (where there are 6 consecutive spaces) - the extra spaces are getting stripped and the resulting code is ETEX14 0001 - I have searched for where this is happening and not been able to find it or find any work-around. I have checked that I am able to read a QR code with the spaces correctly encoded by using a different tool to generate the QR code so I am reasonably sure the code is being "minified" somewhere in mPDF and excess spaces stripped out. I have not been able to find any option or configuration change that will stop this happening despite searching for several hours and attempting many configuration changes. I apologize if this is a configuration issue and not a bug, but I have not been able to get this working.

This is mPDF and PHP version and environment (server/fpm/cli etc) I am using

Using mpdf/mpdf V8.0.10, mpdf/qrcode V1.2.0 running under PHP 7.4 on Apache V2.4.41

This is the PHP code snippet I use

<?php

    // Require composer autoload - create $mpdf object
    require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
    $mpdf = new \Mpdf\Mpdf([
        'format' => 'A4-P',
        'mode' => 'utf-8',
        'margin_left' => 0,
        'margin_right' => 0,
        'margin_top' => 0,
        'margin_bottom' => 0,
        'margin_header' => 0,
        'margin_footer' => 0,
        'nonPrintMargin' => 4
    ]);  //MPDF8

//Create HTML page in variable $html...(not shown)

$Location = 'EX14';
$BarcodeLocation = 'ET' . str_pad($Location, 10, " ", STR_PAD_RIGHT) . '0001';
$html .= "<barcode code=\"$BarcodeLocation\" type=\"QR\" class=\"barcode\" size=\"0.3\" error=\"M\" disableborder=\"1\" />\n";

//much later...
$mpdf->WriteHTML(trim($html),\Mpdf\HTMLParserMode::DEFAULT_MODE);
$mpdf->Output("Int_Doc_A4_Labels.pdf", "I");

This is the HTML/CSS code snippet I use

All is above...
ianhattti commented 1 year ago

Just an update on this: this isn't the mpdf/qrcode library doing this. I can edit the mdpf.php file to force sending multiple spaces and the QR code is correctly generated. The spaces must be being stripped before they get sent to the QrCode function, presumably somewhere in Mpdf.php...