- list images with command:
pdfimages -j -png file.pdf img
- run list-code-images.py to find the dark theme code images
- invert these image to make them light theme code:
for f in `cat file.code-images.txt`; do convert $f -channel RGB -negate inversed/$f done
- find a way to replace images in a pdf with code (but I gave up here)
I end up using PyMuPDF to invert dark theme code images and save them in the same position using replace-images.py.
You will need to install these packages:
pip install fitz PyMuPDF
Alhamdulillah, all images replaced. This is an illusion of replacement, because the new images are placed in top of the old images. I think there exists some possible ways to really replace using Document.update_object or Document.update_stream provided by PyMuPDF package.