News for hackers. Stuff that matters.
Re:CSS for printing to paper by bradgessler on Sunday March 03, 2024 @05:44PM (#39585232)
Browser support for printing is so bad that I'm going to have to create a native app for https://www.thingybase.com to have a streamlined workflow of printing labels to a thermal label printer.

It works now, but first you have to download a PDF and print that. Google Docs does this too when you hit "Print".

I've tried hacks like load the PDF in an iframe and use some JavaScript to print that, but then I get footers with the URL of the webpage, which doesn't work for my purposes.

If you work on Chrome/Blink, Safari/Webkit, or Firefox/Mozilla please please please at least get the hacks working!

A CSS standard would be great, but really I'd be happy if I could call a function like `windows.print("/document.pdf")` and have it print the PDF without all the footer/headers stuff.

Re:CSS for printing to paper by thekingshorses on Sunday March 03, 2024 @06:05PM (#39585358)
Well, you can use .pdfp to print it on Windows.

You will need adobe acrobat (free). This is a very old trick but still works on Windows 10. We use it with the latest edge.

I do wish that the browser had a special direct printing option.

https://groups.google.com/g/comp.text.pdf/c/dHuBMsaovco?pli=...

Re:CSS for printing to paper by voussoir on Sunday March 03, 2024 @06:27PM (#39585489)
I realize you're working on the software side rather than the hardware side, and you mentioned you're trying to support existing printers, but your comment reminded me of something I'd like to throw out there:

I would like to have a thermal printer that plugs into the computer via USB and appears as a mass storage device. When you drop an image file (PNG, BMP) into it, it prints it out. A config file would tell the printer what paper stock you have loaded. This way the computer does not need any special drivers, and it would be so stupidly easy to write programs that generate image files to be printed. I think more hardware should take advantage of filesystem operations as a control method.

If someday you ever think about producing a first-party thingybase printer...

Re:CSS for printing to paper by ramses0 on Sunday March 03, 2024 @06:44PM (#39585599)
Glue + screw a Pi underneath a thermal printer???!?
Re:CSS for printing to paper by ethanbond on Sunday March 03, 2024 @08:05PM (#39586047)
This is a really cool project. What’s the pricing?!
Re:CSS for printing to paper by bradgessler on Sunday March 03, 2024 @08:36PM (#39586221)
Free up to 100 items, then $59.98/year ($4.99/mo billed annually).
Re:CSS for printing to paper by IgorPartola on Sunday March 03, 2024 @05:54PM (#39585299)
I’ve worked with thermal printers and they are actually quite capable. They have drawing primitives that allow you to lay out basic graphics and the one I was working with even had basic font support. A native driver is definitely the way to go with these.
Re:CSS for printing to paper by bradgessler on Sunday March 03, 2024 @05:58PM (#39585318)
> 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.

Re:CSS for printing to paper by blorenz on Sunday March 03, 2024 @08:26PM (#39586166)
I 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.
Re:CSS for printing to paper by bradgessler on Sunday March 03, 2024 @08:56PM (#39586333)
I’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.
Re:CSS for printing to paper by rudasn on Monday March 04, 2024 @01:20AM (#39587543)
If 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.

Re:CSS for printing to paper by djbusby on Sunday March 03, 2024 @07:16PM (#39585775)
Open the PDF in a new window and call window.print() on it.
Re:CSS for printing to paper by bradgessler on Sunday March 03, 2024 @07:18PM (#39585786)
That doesn’t work on iOS—you get the URL in the footer at the bottom of the page.
Re:CSS for printing to paper by rudasn on Monday March 04, 2024 @02:11AM (#39587782)
Maybe you can use pdf.js from mozilla to render the pdf in the browser and trigger the print function from your js?
Re:CSS for printing to paper by bradgessler on Monday March 04, 2024 @02:13AM (#39587801)
I’ve tried that and it didn’t work. It actually didn’t work as well as throwing a PDF at it.
Re:CSS for printing to paper by Boltgolt on Sunday March 03, 2024 @08:48PM (#39586282)
You can force remove the URL and page numbers on the printout by setting the @page rule padding to 0
Re:CSS for printing to paper by hiccuphippo on Tuesday March 05, 2024 @02:52PM (#39608398)
I did this a long time ago. Made a small qt app and hooked it to the `print://` scheme in the Windows registry, so in the web server I just had to change a link to `print://example.com/whatever` and the app would load the url and send it to the printer, for the website's domain it would skip any confirmation.