I built Price Tag Printer, a utility tool for retail teams to automate price label generation. Retail operations demand quick updates for thousands of products without introducing UI lags or formatting errors. The solution leverages Next.js App Router, combining client-side interactivity with a high-performance backend PDF generator.
The Architecture: React 19 and Next.js 15 App Router
To make the application robust and modular, I structured the boundaries clearly. Client-side interactions handle catalog ingestion, search, filter operations, and theme configuration, while a serverless Next.js API endpoint handles heavy rendering tasks. This uncouples CPU-heavy PDF generation from the client browser, ensuring that low-end POS terminals or tablet devices used in retail stores remain fully responsive during bulk printing operations.
Zustand State Persistence and Zod Validation
Importing spreadsheet data can be highly error-prone due to unpredictable column structures, formatting types, or empty fields. I built a flexible ingestion layer that handles raw clipboard data, direct Excel (XLSX) file parsing, and Google Sheets API inputs. Once imported, the data is normalized through a strict Zod schema before hitting the state layer. To store this state securely without server-side storage overhead, I configured Zustand stores with persistent local storage middleware.
Optimizing Excel Sheet Parsing with Stream Web Workers
Parsing spreadsheets containing over 5,000 rows inside the browser main thread causes visible interface stutter. To prevent this, I offloaded the entire parser execution layer into a dedicated Web Worker script. The spreadsheet buffer is transferred to the worker thread using Transferable Objects, which avoids copying memory. The worker processes the sheet in chunks and passes normalized JSON records back, keeping the user interface active and responsive.
- Schema Normalization: Zod parsing converts price formats, strips whitespace, and flags formatting anomalies prior to rendering.
- Transactional Updates: Items are updated in batches to avoid triggering multiple component re-renders during 10,000-row imports.
- Offline Resilience: Because state persists locally, store employees can close the app or lose connection without losing their imported price tags.
Designing Print-Ready Layout Grids in CSS
Designing printable grids requires moving away from traditional responsive layouts. I designed my printing stylesheets with rigid physical dimensions like millimeters (mm) and inches (in) and set the browser margins to zero using the CSS @page directive. I also declared break-inside: avoid on the price tag container element, which ensures that cards are never cut in half at page breaks, keeping prints clean and aligned.
- Physical Millimeter Scaling: Aligning layouts to exact millimeter dimensions (e.g. 50mm x 30mm) to match standard industrial price label sizes.
- Background Gradient Forcing: Injecting the -webkit-print-color-adjust: exact rule to prevent browsers from stripping background fills and branding gradients.
Headless Rendering via Headless Chrome & CSS Print
While client-side libraries like jsPDF are suitable for simple documents, they struggle under high volumes, causing browser tabs to crash or generating bloated files. To solve this, I designed a hybrid rendering system. For immediate feedback, the client uses HTML5 Canvas to preview tags instantly. For final printing, the client sends the payload to a backend API route. The API runs a headless Puppeteer instance, parses the styled HTML template, and applies print-specific CSS options like page breaks and exact sizing rules.
Managing Puppeteer Page Pools on Serverless Instances
Initializing a new browser instance for every export request introduces severe latency. I optimized this on the server side by maintaining a pool of pre-warmed Puppeteer tabs. The API borrows a tab from the pool, inserts the HTML grid, compiles the PDF directly in memory, and returns the binary stream to the socket, bypassing disk writing overhead entirely and cutting response times to under a second.
“Browser printing is not about layout screenshots; it is about structuring printable semantic grids.”
“Print CSS is the forgotten art of web development; standard divs become physical objects on real paper.”
Forcing background colors in print styles requires specific CSS properties: always verify color rendering on various OS engines as PDF exports differ.
By using this hybrid pipeline, the application generates a lightweight, vector PDF of 10,000 price tags in under 4 seconds, optimized for industrial print shops.
Danya Yudin (Sabraman)
Designer & Frontend Engineer
Design-led frontend and product developer specializing in web applications, interface design, and Telegram systems.