Back in the early days of Linux (~1993) or so, I was trying to convince my workgroup in grad. school that Linux was a nice alternative for running our numerical simulations (in C). But I knew I had to get the graphics working, since no one wanted to use a text-only interface. It was a Dell PC using some graphics card; the word 'tulip' is in the fog of my memory. The graphics driver was not loading, giving some error about a reference not being found in the .o file. I didn't know what to do, so I loaded up the .o file in vi, searched for the offending reference, edited it out and saved the .o file. From then on the graphics works great!
Sometime in my teen years, I had an insatiable desire to..download..all these expensive programs and play around with them. One day I got ahold of Acronis Disk Director and did some repartitioning of some flash drives I had. If I remember correctly, it had the ability to repartition the currently utilized system drive via some built-in boot environment. Well, I had to try it out. Now is a good time to mention that I was doing this on old Toshiba Satellite that would shutdown after overheating sometimes. As you can expect, the repartitioning failed at some point in the middle because the laptop shut off. What remained was an unbootable drive and a teenager that really didn't know what the problem was, let alone how to fix it.
In my voyages of curiosity, I happened to have a gParted liveUSB laying around. I booted into it, took a look at the main drive on the laptop, and I noticed a few KB or MB of free space before the main partition. I thought this was weird for some reason and decided to use gParted to "shift" the whole partition to the left (the beginning of the drive). After some time it finished and booted up into my Windows install with zero issues. To this day, I am equally baffled and amazed that it worked.
I've implemented recently just the same thing, but for SVG -> PNG conversion. I found that SVG rendering support is crap in every conversion tool and library I've tried. Apparently even Chrome has some basic features missing, when doing text on path for example. So far Selenium + headless Firefox performs the best ¯\_(ツ)_/¯
I wrote a Python package [1] that does something similar! It allows the generation of images from HTML+CSS strings or files (or even other files like SVGs) and could probably handle PDF generation too.
It uses the headless version of Chrome/Chromium or Edge behind the scenes.
Writing this package made me realize that even big projects (such as Chromium) sometimes have features that just don't work. Edge headless wouldn't let you take screenshots up until recently, and I still encountered issues with Firefox last time I tried to add support for it in the package. I also stumbled upon weird behaviors of Chrome CDP when trying to implement an alternative to using the headless mode, and these issues eventually fixed themselves after some Chrome updates. [1] https://github.com/vgalin/html2image
Yeah it's the same concept, instead of .screenshot you do .pdf in pupetteer.
But with pdfs the money is on getting those headers and footers consistent and on every page, so you do need some handcrafted html and print styling for that (hint: the answer is tables).
I've seen a bit of SaaS and legacy websites-with-invoice-system doing that, with e.g. wkhtmltopdf. It isn't a lightweight solution, but it's a good hammer for a strange nail, a lot of off-the-shelf report systems suck.
I did the same. We had a tool that would let you export to pdf. That pdf would be sent to our customers. Initially we just used the print functionality in the users browser, but that caused output to vary based on the browser/os used.
People complained that the PDFs generated were slightly different. So instead I had the client send over the entire html in a post request and open it up in a headless chrome with --print-to-pdf and then sent it back to the client.
I mean browsers are built for and the best at displaying html+css. Given that they are "living standards", very few other programs can hope to keep up.
I had Chromium component added to a project just to show the users the help file which was a giant PDF document. The PDF file was from a 3rd part vendor who didn't know better/refused to change the system so we had to show it "as is" to the users. Any PDF reader component we tried failed because the PDF file had some crappy features in it that none of those component knew how to parse. Chromium engine, for its hate that gets nowadays, had no problem with any of those PDF files.
Some 10+ years ago on a small LAN party, we hooked up a tower PC to a projector to show some stats, last few lines of an IRC channel, those kind of things. For some reason, we directly started the application in X (the display system), but at regular intervals, the projector would stop working. Of course! Screen blanking. Having no window manager or other means* of controlling this, the projector would of course keep on displaying our lovely application if we would move the mouse once in a while, or type on the keyboard.
Instead of tasking someone to move the mouse once in a while, we taped a wired, optical mouse to the tower PC at the front. At the time, CD/DVD players were still abundant, so this PC also contained one. We did know about the eject(1) tool, as well as its option to close the tray again (eject -t). From that moment on, the solution for our screen blanking problem was fixed:
while true; do eject /dev/cdrom; sleep 5; eject -t /dev/cdrom; sleep 30; done;
(this would eject the CD/DVD drive, wait five seconds, then close it again, and wait 30 seconds before starting the same sequence again)
This would cause the optical mouse to detect movement, send this to the PC, and in the end keep the projector on. * we would later discover the xset(1) tool and its DPMS/screen saver settings. But that would've eliminated the periodic, comedic noise of the CD/DVD drive and the wired mouse bumping on the tower PC, so we kept the while loop intact during the rest of the LAN party.
Comments (499) 174 threads
Earlier commentsIn my voyages of curiosity, I happened to have a gParted liveUSB laying around. I booted into it, took a look at the main drive on the laptop, and I noticed a few KB or MB of free space before the main partition. I thought this was weird for some reason and decided to use gParted to "shift" the whole partition to the left (the beginning of the drive). After some time it finished and booted up into my Windows install with zero issues.
To this day, I am equally baffled and amazed that it worked.
Turns out, if you want to turn html+css into pdfs quickly, doing via a browser engine is a "works really well" story.
Writing this package made me realize that even big projects (such as Chromium) sometimes have features that just don't work. Edge headless wouldn't let you take screenshots up until recently, and I still encountered issues with Firefox last time I tried to add support for it in the package. I also stumbled upon weird behaviors of Chrome CDP when trying to implement an alternative to using the headless mode, and these issues eventually fixed themselves after some Chrome updates.
[1] https://github.com/vgalin/html2image
But with pdfs the money is on getting those headers and footers consistent and on every page, so you do need some handcrafted html and print styling for that (hint: the answer is tables).
People complained that the PDFs generated were slightly different. So instead I had the client send over the entire html in a post request and open it up in a headless chrome with --print-to-pdf and then sent it back to the client.
Instead of tasking someone to move the mouse once in a while, we taped a wired, optical mouse to the tower PC at the front. At the time, CD/DVD players were still abundant, so this PC also contained one. We did know about the eject(1) tool, as well as its option to close the tray again (eject -t). From that moment on, the solution for our screen blanking problem was fixed:
(this would eject the CD/DVD drive, wait five seconds, then close it again, and wait 30 seconds before starting the same sequence again)This would cause the optical mouse to detect movement, send this to the PC, and in the end keep the projector on.
* we would later discover the xset(1) tool and its DPMS/screen saver settings. But that would've eliminated the periodic, comedic noise of the CD/DVD drive and the wired mouse bumping on the tower PC, so we kept the while loop intact during the rest of the LAN party.
All comments shown.
Couldn't load more comments. Check your connection and try again.