0

Looking for ways to change the color of all text in a PDF to black using an open-source command-line tool (or package) while ensuring that text is rendered as text.

Thanks to some answers on SO, found a command to convert the PDF to grayscale.

gs -o op.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -f ../ColorTest.pdf

Input PDF: enter image description here

Output PDF: enter image description here

PDF Sample here

However, the requirement is for the text to be black.

Any detailed steps or pointers on how this can be accomplished would be highly appreciated.

qwertynik
  • 118
  • 2
  • 10
  • 1
    *"the requirement is for the text to be black."* - Even if the text is located on a black background? – mkl Mar 14 '22 at 11:46
  • To begin with, yes @mkl that's ok. Because most likely the source PDFs are known. Having some workarounds to avoid making the text as black on black background would be great - but not the first priority, at least for now. – qwertynik Mar 14 '22 at 11:57
  • 1
    RTFM: https://ghostscript.com/doc/9.55.0/Use.htm#Rendering_parameters But you will need to be using a recent version of Ghostscript. If I might point out; it's better to post example PDF files than pictures of PDF files, that way people can test them. – KenS Mar 14 '22 at 12:04
  • Certainly, @KenS. Attaching PDF files makes it easier to test. Had attached a while ago. Hopefully, that helps. – qwertynik Mar 14 '22 at 12:06
  • Did attempt to read the manual, however, could not find something relevant for the use-case at hand. – qwertynik Mar 14 '22 at 12:07
  • 1
    @qwertynik You mention that you are looking for a command line tool. Programming one yourself using some PDF library is no option? – mkl Mar 14 '22 at 13:14
  • 1
    Try looking on the page I linked to for 'BlackText'..... You'll have to scroll down a little but it is pretty clear. The attached file renders the text in black for me with the appropriate parameter. – KenS Mar 14 '22 at 13:21
  • Searching for 'Black' is one of the things that was done on the documentation page. `-dBlackText` is the param that was tried. But it didn't help. Looks like that's because of using an older version of Ghostscript. The version is 9.26. @KenS, can you confirm on which version this could work? – qwertynik Mar 15 '22 at 06:52
  • mkl - By tool, packages like Ghostscript, xpdf, or mupdf are being referred to and not any custom command line app. – qwertynik Mar 15 '22 at 06:54
  • @KenS as you rightly mentioned the BlackText option does indeed work. Had to download the latest package from here to experiment: https://ghostscript.com/releases/gsdnld.html – qwertynik Mar 15 '22 at 07:48
  • 1
    Well the 'current' documentation refers, unsurprisingly, to the current release (9.55.0), as does the documentation under doc/9.55.0. 9.26 is 3 years old, and the documentation for that is no longer on the website, although it is in the source code. Obviously you need to refer to the correct documentation for the version you are using! – KenS Mar 15 '22 at 08:31
  • @KenS Yes, certainly. Missed it there. – qwertynik Mar 15 '22 at 08:46

1 Answers1

0
cpdf -blacktext ColorTest.pdf -o out.pdf
focog77269
  • 104
  • 5