Learn how to generate barcode and QR code stickers in Laravel using Milon Barcode and Snappy PDF. Create print-ready PDFs, embed product metadata, and print professional labels for inventory and retail.


Barcodes and QR codes are crucial for inventory management, product labeling, and retail operations. Using Laravel, you can automate sticker generation, create print-ready PDFs, and print professional-quality labels efficiently.
In this guide, you’ll learn:
How to install required Laravel packages
Generate barcodes and QR codes
Display codes in Blade templates
Export labels as PDFs with custom sizes
Add metadata to QR codes
Print professional stickers
By the end, you’ll have a complete sticker generation system ready for production.
We’ll use two popular packages:
Milon Barcode – Generate 1D/2D barcodes and QR codes.
Laravel Snappy – Convert Blade views into PDFs with custom dimensions.
Install via Composer:
composer require milon/barcode
composer require barryvdh/laravel-snappyPublish Snappy’s configuration:
php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"Note: Snappy requires wkhtmltopdf. Install it and set the binary path in
config/snappy.php.
Milon Barcode supports HTML output and Base64 images.
Barcode (Code128):
{!! DNS1D::getBarcodeHTML('1234567890', 'C128') !!}QR Code Example:
{!! DNS2D::getBarcodeHTML('https://yourapp.com', 'QRCODE') !!}For images instead of inline HTML:
<img src="data:image/png;base64,{!! DNS1D::getBarcodePNG('1234567890', 'C128') !!}" />
<img src="data:image/png;base64,{!! DNS2D::getBarcodePNG('https://yourapp.com', 'QRCODE') !!}" />Create a controller method to generate PDFs:
public function generateStickers(Request $request)
{
$request->validate([
'code_type' => 'required|string|in:barcode,qrcode',
]);
$products = Product::all();
$code_type = $request->code_type;
$pdf = PDF::loadView('products.stickers', compact('products', 'code_type'))
->setOption('page-width', '2in')
->setOption('page-height', '1in')
->setOption('margin-top', 0)
->setOption('margin-right', 0)
->setOption('margin-bottom', 0)
->setOption('margin-left', 0)
->setOption('disable-smart-shrinking', true);
$fileName = $code_type === 'qrcode' ? 'qrcodes.pdf' : 'barcodes.pdf';
return $pdf->download($fileName);
}
File: resources/views/products/stickers.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Stickers</title>
<style>
html,
body {
width: 2in;
height: 1in;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
font-size: 7px;
}
.sticker {
width: 2in;
height: 1in;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0.05in;
text-align: center;
overflow: hidden;
}
.sticker img {
max-width: 1.8in;
max-height: 0.6in;
}
.label {
margin-top: 0.05in;
font-size: 7px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
</style>
</head>
<body>
@foreach ($products as $product)
@php $codeData = $product->product_code ?? 'UNKNOWN'; @endphp
<div class="sticker">
@if ($code_type === 'qrcode')
<img src="data:image/png;base64,{!! DNS2D::getBarcodePNG($codeData, 'QRCODE') !!}" />
@else
<img src="data:image/png;base64,{!! DNS1D::getBarcodePNG($codeData, 'C128') !!}" />
@endif
<div class="label">{{ $product->product_name }}</div>
</div>
@endforeach
</body>
</html>
You can embed extra product details in QR codes:
$fields = [
"Code:{$product->product_code}",
"Name:" . substr($product->product_name, 0, 40),
];
if ($product->serial_number) {
$fields[] = "Serial:{$product->serial_number}";
}
$barcodeData = implode('|', $fields);
Once your PDF is ready:
Download and open it in a PDF viewer.
Print on 2in × 1in Avery-style sticker sheets.
Apply labels to products for instant scanning.
This ensures uniform, scannable, professional-grade labels for inventory or retail use.
By using Milon Barcode and Laravel Snappy, you can:
Generate 1D and 2D barcodes & QR codes
Export custom-sized, print-ready PDFs
Embed product metadata into QR codes
Print professional-quality stickers
This approach is scalable, flexible, and ready for production, making it ideal for inventory tracking, retail labeling, or warehouse management.
You need Milon Barcode for generating 1D/2D codes and Laravel Snappy to export Blade templates as PDFs. Both are installable via Composer.
Yes! You can embed multiple product fields such as product code, name, and serial number into a QR code. This makes scanning more informative and useful for inventory management.
Common professional labels are 2 inches × 1 inch. Snappy allows you to set custom page width and height for each PDF.
After generating the PDF:
Download and open it in a PDF viewer.
Print on Avery-style sticker sheets.
Apply labels to products for uniform and scannable stickers.
Yes. The combination of Milon Barcode and Laravel Snappy is scalable. You can generate PDFs in bulk for hundreds or thousands of products.