6 ms·
Show HN: PDF Inverter for macOS (In Golang) Darken Your PDFs
- kowlo 6y agoA browser plugin that I use for Safari/Chrome/Firefox/Edge does this too (https://darkreader.org https://darkreader.org). > Configure the dark theme: brightness, contrast and sepia. Enable for all websites or particular domains. Works for PDFs too. No affiliation.
- skunkworker 6y agoI like dark reader too, with the most gpu intensive mode and sepia it makes for some really good dark modes for most websites. And I’ve built dark mode css off of it as an inspiration. Edit: the "Dynamic" (GPU) mode doesn't work on all sites. On HN I'll use Filter+ with the settings -20 brightness, contrast off, sepia +30, grayscale off. While on Github I'll do -5, 0, +30, 0. Mainly just tweaking the brightness while having Sepia on most sites.
- deleted 6y ago[deleted]
- glushkov 6y agoNot sure why this needs a dedicated application, you can do this in Chrome or FF with a single line of JS: javascript:(function(){viewer.style = 'filter: grayscale(1) invert(1) sepia(1) contrast(75%)';})()
- ketamine__ 6y agoDidn't work for me. I'm using Brave.
- Ciantic 6y agoHmm, for me, following works with Google Chrome PDF viewer: Bookmarklet javascript:(function() { var v = document.getElementsByTagName("html"); v[0].style.background = "white"; v[0].style.filter = "invert(90%) sepia(60%) brightness(70%)"; v[0].style.backgroundColor = "black"; document.getElementsByTagName("body")[0].style.background = "white"; })();
- anamexis 6y agoThat does not work with the Chrome PDF viewer for me. (Chrome 87, Mac)
- sroussey 6y agoWhich PDF viewer? 87 has a test running for a new version. chrome://flags/#pdf-viewer-update
- tapia 6y agoYou can do this on-the-fly with Zathura... in Linux
- xrisk 6y agoZathura also exists on macOS..
- ognarb 6y agoYou can also do it in Okular.
- Shared404 6y agoAlso GNOME's default PDF reader. Don't know what it's called though. Edit: It appears to be Evince [0] [0] https://en.wikipedia.org/wiki/Evince https://en.wikipedia.org/wiki/Evince
- afranchuk 6y agomupdf also supports this.
- gitgud 6y agoyep, seems to be built right into gnome on Ubuntu https://imgur.com/a/CA6zoWf https://imgur.com/a/CA6zoWf
- bartvk 6y agoVery cool. I've been searching for a PDF viewer which can do this under macos, but just converting is fine too.
- xyst 6y agohttps://github.com/rootVIII/pdfinverter/blob/master/utils.go#L88 https://github.com/rootVIII/pdfinverter/blob/master/utils.go... using go to wrap a python script - this is some "hacker man" stuff right here
- pepemon 6y agoBut using boring Python only, you are unable to add fancy Go mention to the submission's title!
- Hamuko 6y agoUsing Go to wrap a Python script that is mostly just a wrapper for some macOS APIs.
- TheDong 6y agoAnd written to be less readable with e.g.: return bytes.ReplaceAll(script, []byte{0x09}, []byte{0x20, 0x20, 0x20, 0x20}) instead of bytes.ReplaceAll(script, []byte("\t"), []byte(" ")) Skimming through the code, there's a lot of other pretty basic mistakes. The most egregious is that the use of a python script has a security issue. Let's see if you can spot it, it's in these lines: tmp := fmt.Sprintf("/var/tmp/invertpdf--%s/", time.Now().Format("20060102150405")) os.Mkdir(tmp, 0700) WriteText(tmp+"pngtopdf.py", GetPDFConv()) // later execute that .py file So, what's the issue? Well, using a predictable temporary directory and then not checking for an error in `mkdir` means that an attacker can easily create that directory before you do (especially since it's a predictable name based on the time), and then write their own python script. That lets another user on your machine run arbitrary code as your user. "But", you might say, "WriteText does an os.Exit if it can't write the file". That doesn't matter. If i create the directory with permissions 777, and then have a program waiting for the python script to be written in order to replace it with a malicious script, Mkdir will error (dir already exists), but WriteText will succeed, and so the vulnerability still happens. This is the sort of dumb vulnerability you get if you don't know that `ioutil.TempDir` exists (or don't know about symlink races, tmpdir races, etc). `ioutil.TempDir("/var/tmp", "invertpdf-")` would be the more secure way to do this, though obviously you still should check that error too. There's a lot of other problems with this program, but this vulnerability is the most obvious.
- wzy 6y agoSo PDF viewers apps on MacOS do not support color changing by way of accessibility options?
- Someone 6y agoWhy would that be a feature of an application? That’s an OS function (https://www.apple.com/accessibility/mac/vision/ https://www.apple.com/accessibility/mac/vision/)
- xdavidliu 6y agoone bad thing about this is that if you also like to redshift your color temperature, you cannot have that and the OS-level invert on at the same time (last time I checked). Hence, inverting the pdf file itself allows you to have the best of both worlds.
- the8472 6y agoSeems to invert RGB values without performing a hue rotation, that leads to colors also being changed, not just the brightness.
- getpolarized 6y agoWe went full dark mode when we released the 2.0 version of our app which has PDF and EPUB support: https://getpolarized.io/2020/10/05/Polar-2-0-Release.html https://getpolarized.io/2020/10/05/Polar-2-0-Release.html the issue we had was that we were using a CSS filter like other commenters mentioned. The problem is that it inverts images too and pdfjs doesn't actually specify which parts of the document are an image as it's just writing to a canvas. My plan moving forward is to fix pdfjs so it can invert natively and the actual canvas is inverted so that images won't be inverted. I think figures would STILL be a problem though. EPUBs are much easier and we're not inverting there because we can see which one is an img.
- minitech 6y agoDidn’t the getpolarized spam used to come from a different account?
- brian_herman 6y agoIn the Sumatra pdf reader you can edit the config so it inverts the colors.
- drukenemo 6y agoI like it, thanks!