I was browsing through my old OneNote posts, and found one record of an adventure I planned to record when I got another blog. So here it is. This is happened quite a while ago, early 2018.
I signed up for an in-person Japanese course that was based in San Jose. They had an agreement to use a Sony building for classes after work hours. Pretty cool.
Then came the obligatory textbook purchase. The standard intermediate to advanced Japanese textbook of choice is Tobira. I've only used the Nakama textbooks in college, so I needed to get a physical copy.
I planned to print Tobira from a digital copy, of course. I looked into print-on-demand services that take an uploaded PDF, print it, bind it with options of my choosing, and ship it to my door. Very convenient, and I don't even have to go out the door.
The first conflict that popped up is that digital copies of Tobira looked quite awful. The scans were unaligned, but the biggest issue was the poor contrast. I printed out a page on my own printer to test, and it's a good thing I did. The print version looked even lighter than the PDF.
'Twas time to take matters into my own hands. If the PDF Tobira had shit contrast, then I had to do some post-processing and make a better PDF to send off for printing.
There's a really neat library for all sorts of image manipulation called ImageMagick. There's another neat library for PDF manipulation called Ghostscript.
The plan: 1. Convert PDF into PNGs. 2. Batch adjust contrast with ImageMagick. 3. Convert PNGs back into PDF. 4. Send off to print service. 5. Profit!
This is what the original Tobira PDF looked like, before any contrast adjustments.
The days of malding at getting the right ImageMagick options and contrast will be omitted from this blog post. Ultimately, I could convert from PDF to PNG and adjust contrast in one operation.
magick convert -verbose -density 300 -trim -quality 00 -brightness-contrast -40x50 "Letter size.pdf" output\page.png
Isn't the contrast looking pretty sweet now? When I finally got it right I felt a sense of pride and accomplishment.
The 2 inch PDFs had to be converted back to proper A4 letter size PDFs before printing or I'd have a textbook for ants.
magick convert -quality 100 -units PixelsPerInch -density 300 -page letter page-%d.png[0-335] final.pdf
Kek, another unexpected problem. Whatever the conversion did, the page aligned too far to the right, so content got cut off.
The problem can be fixed with a +repage, which will reset image offsets. And now it's done! I also changed the density from 300 to 72, which I believe is resizing the PDF back to normal people proportions.
magick convert -quality 100 -units PixelsPerInch -density 72 -page letter page-%d.png[0-335] +repage testing.pdf
The final PDF is still ~600MB. Which is pretty crazy by PDF standards, but considering I converted it into PNG and back, the PDF got overloaded with a ton of image data. I'm sure if I spent more time that I didn't have before classes started figuring out how to use Ghostscript to change the contrast without needing to convert to PNGs first, the filesize could be comparable to the original.
And thus this beauty of a PDF got sent off for printing. Cost me $24.32. HA. Way less than if I directly bought the textbook.
Joke's on me. Turned out the Tobira PDF was missing dozens and dozens of random pages. I had to look through another classmate's book for a couple classes. I listed out the number of missing pages, found another Tobira PDF that contained the pages, and had to print those out. They don't fit within the print service's binding so they were ungracefully jammed in. I also added the missing PDF pages into the final Tobira PDF as future-proofing.
Still a victory, we take these.