Add optional direct thermal printing to Niimbot printers from the lab… - #1445
Add optional direct thermal printing to Niimbot printers from the lab…#1445jaimelaborda wants to merge 1 commit into
Conversation
…el generator Adds a "Print to Niimbot" panel to the label generator dialog that sends the generated label straight to a Niimbot thermal printer (e.g. B1) over Web Bluetooth, without a PDF print dialog or printer driver. The existing server-side DomPDF label is reused as-is: a new Stimulus controller rasterizes the PDF preview page-by-page with pdf.js at the printer's native resolution, converts it to a 1-bit bitmap and prints it via the niimbluelib library. No changes to the PHP label pipeline are required. The feature is disabled by default and gated behind the NIIMBOT_ENABLED environment variable, since it is only useful for users who own such a printer. - Add @mmote/niimbluelib and pdfjs-dist dependencies - New assets/controllers/pages/niimbot_print_controller.js - Print options (copies, density, label type, rotation, B/W threshold) in the label dialog, gracefully disabled when Web Bluetooth is unavailable - NIIMBOT_ENABLED env flag (off by default), wired through parameters.yaml and a Twig global, documented in .env - English translations and documentation Requires a Chromium-based browser and a secure context (HTTPS or localhost).
|
Thanks for the PR. I havent looked into details yet, but some remarks:
|
|
Thanks for the quick look — all four points make sense. Here's how I'd like to address them, with one question on each of the bigger two. 1. Configuration via the settings systemAgreed, this shouldn't be env-only — it isn't security critical. I'll move it to a #[Settings(name: "thermal_printing", label: new TM("settings.misc.thermal_printing"))]
#[SettingsIcon("fa-print")]
class ThermalPrintingSettings
{
use SettingsTrait;
#[SettingsParameter(
label: new TM("settings.misc.thermal_printing.enabled"),
description: new TM("settings.misc.thermal_printing.enabled.help"),
envVar: 'bool:THERMAL_PRINTING_ENABLED', envVarMode: EnvVarMode::OVERWRITE)]
public bool $enabled = false;
}That lets me drop the Question: where would you prefer it to live — a new section embedded in 2. Lazy loadingAgreed, and I think it's worth doing even though it's "just a comment", because right now the controller is bundled for everyone regardless of the flag (the I'll add 3. Making it genericAgreed, and I'd like to get your opinion on the shape before I refactor. What I have in mind: The controller stays printer-agnostic: it picks a driver by id from a Stimulus value and This should fit ZPL/EPL (#489) reasonably well, since One thing worth flagging: networked ZPL printers (raw TCP/9100) can't be reached from the browser at all, so that path would need a server-side sibling of the driver interface. Direct-attached ZPL over Web Serial/USB would fit the browser-side interface fine. My inclination is to define the JS driver interface now and not add a PHP-side driver registry until someone actually implements the network path — but if you'd rather I design both seams up front, I'm happy to. Question: does the above match what you had in mind, or would you prefer a literal abstract base Stimulus controller that 4. dompdf rendering to a bitmap directlyI looked into this, and I don't think it works for Part-DB labels specifically — dompdf's GD backend can't render SVG. Part-DB embeds every barcode/QR as an SVG data URI (
So a GD-rendered label would fail on essentially any label with a barcode, which is most of them. Unless I'm missing another route (Imagick on the CPDF output?), I'd stick with pdf.js. There are two smaller arguments for rasterizing client-side anyway: the printer is attached to the client, and the correct pixel dimensions depend on capabilities that are only known after connecting (e.g. the B1 reports 203 dpi / 384 px printhead), so doing it in the browser keeps that loop local. And with lazy loading the pdf.js cost is only paid by people who actually print. That said — if networked ZPL ever lands, server-side rasterization becomes necessary for it, so I'd expect that to appear as a sibling path rather than a replacement. I'll hold off on the refactor until you've weighed in on 3 (and the placement question in 1), then push everything in one go. |
…el generator
Adds a "Print to Niimbot" panel to the label generator dialog that sends the generated label straight to a Niimbot thermal printer (e.g. B1) over Web Bluetooth, without a PDF print dialog or printer driver.
The existing server-side DomPDF label is reused as-is: a new Stimulus controller rasterizes the PDF preview page-by-page with pdf.js at the printer's native resolution, converts it to a 1-bit bitmap and prints it via the niimbluelib library. No changes to the PHP label pipeline are required.
The feature is disabled by default and gated behind the NIIMBOT_ENABLED environment variable, since it is only useful for users who own such a printer.
Requires a Chromium-based browser and a secure context (HTTPS or localhost).