Refactor QR code PDF generation to improve layout and add automatic print functionality

This commit is contained in:
dhanabalan
2025-07-28 18:01:50 +05:30
parent 83f98d9e83
commit b0d2132e25

View File

@@ -24,15 +24,15 @@ class PalletController extends Controller
$qrBinary = $output->output($qrCode, 100); $qrBinary = $output->output($qrCode, 100);
$qrBase64 = base64_encode($qrBinary); $qrBase64 = base64_encode($qrBinary);
$html = ' return '
<html> <html>
<head> <head>
<style> <style>
body { margin: 0; padding: 0; width: 60mm; height: 14mm; font-size: 10pt; font-family: DejaVu Sans, sans-serif; } body { margin: 0; padding: 0; width: 60mm; height: 14mm; font-size: 10pt; font-family: DejaVu Sans, sans-serif; }
.sticker-table { width: 60mm; height: 14mm; border-collapse: collapse; } .sticker-table { width: 60mm; height: 14mm; border-collapse: collapse; }
.qr-cell { width: 14mm; text-align: left; vertical-align: middle; padding-left: 6mm; padding-top: 2mm; } .qr-cell { width: 14mm; text-align: right; vertical-align: bottom; padding-left: 4mm; padding-top: -6mm; }
.text-cell { text-align: left; vertical-align: middle; font-size: 15pt; padding-left: 4mm; padding-top: 2mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: bold; } .text-cell { text-align: left; vertical-align: middle; font-size: 16pt; padding-left: 4mm; padding-top: 2mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: bold; }
img.qr { width: 18mm; height: 18mm; display: block; } img.qr { width: 13mm; height: 13mm; display: block; }
</style> </style>
</head> </head>
<body> <body>
@@ -46,23 +46,31 @@ class PalletController extends Controller
</td> </td>
</tr> </tr>
</table> </table>
<script>
window.onload = function () {
window.print();
setTimeout(function () {
window.close();
}, 500); // Wait 0.5 seconds before closing
};
</script>
</body> </body>
</html> </html>
'; ';
$mpdf = new Mpdf([ // $mpdf = new Mpdf([
'mode' => 'utf-8', // 'mode' => 'utf-8',
'format' => [60, 14], // 'format' => [60, 14],
'margin_left' => 0, // 'margin_left' => 0,
'margin_right' => 0, // 'margin_right' => 0,
'margin_top' => 0, // 'margin_top' => 0,
'margin_bottom' => 0, // 'margin_bottom' => 0,
'tempDir' => '/var/www/storage/mpdf-tmp', // // 'tempDir' => '/var/www/storage/mpdf-tmp',
]); // ]);
$mpdf->WriteHTML($html); // $mpdf->WriteHTML($html);
$mpdf->Output('qr-label.pdf', 'I'); // // Output PDF to browser for printing
exit; // $mpdf->Output('qr-label.pdf', 'I');
} }
/** /**