Convert pdf file to monochrome #2698
-
How can i convert a file to black and white / monochrome ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
There is no dedicated functions for that. for text and drawings, you should be able to look through contents looking for color operators (CS, cs, SC, SCN, sc, scn, G, g, RG, rg, K, k - see §4.5.7 in pdf 1.7 specification) and replace these lines with G or g operators with the adequate gray definition) but you will have to define your own translation rule. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply. Is it intended to be added to pypdf as a feature at some point or is it out of scope for this library ? Thanks |
Beta Was this translation helpful? Give feedback.
There is no dedicated functions for that. for text and drawings, you should be able to look through contents looking for color operators (CS, cs, SC, SCN, sc, scn, G, g, RG, rg, K, k - see §4.5.7 in pdf 1.7 specification) and replace these lines with G or g operators with the adequate gray definition) but you will have to define your own translation rule.
for images, you can use the
images[ ].replace()
function to replace the image once converted to gray or black