3 ms·
> A native driver is definitely the way to go with these. Not if you need to support a bunch of different printers. For me PDF is the way to go, but browsers
by bradgessler 3y ago
> A native driver is definitely the way to go with these.
Not if you need to support a bunch of different printers.
For me PDF is the way to go, but browsers can't print a PDF via a "Print" button within the HTML, so instead I have to build apps that download the PDF and print it directly through operating system APIs.
- djbusby 3y agoOpen the PDF in a new window and call window.print() on it.
- bradgessler 3y agoThat doesn’t work on iOS—you get the URL in the footer at the bottom of the page.
- blorenz 3y agoI have this in my SaaS, as well. I built an Electron app that ushers the jobs from the cloud to the thermal printer. It all works until there is a failed job and the queue backs up. I haven't quite figured out how to monitor the queue remotely yet.
- bradgessler 3y agoI’m probably going to run the app inside of Electron and print from there, so it will be easier in my case for the users to monitor the queue.
- rudasn 3y agoIf so, then you have a full browser to generate your pdfs on. An approach I have used (more or less): - have a print.html template page - use iframe to render and load the page - either on the print page, or from top frame, call window.print You can use the aforementioned js libraries to generate footers and such, and use any print css. You can test the print layout in your dev tools, no need to wait for browser preview. Note that browsers will try to render thead and tfooter elements on every page their parent table spans, that can be very useful. At work we have a playwright container with express js waiting for incoming requests to load the print.html page and save it as pdf. We're also using volumes so that all data exchange happens in disk and not being passed around in http requests. PDFs that took maybe 30 seconds with weasy print, now take 5 seconds.
- rudasn 3y agoMaybe you can use pdf.js from mozilla to render the pdf in the browser and trigger the print function from your js?
- bradgessler 3y agoI’ve tried that and it didn’t work. It actually didn’t work as well as throwing a PDF at it.