Log of #ghostscript at irc.freenode.net.

Search:
 <<<Back 1 day (to 2021/03/20)Fwd 1 day (to 2021/03/22) >>>20210321 
androclus Hey, all.. Please forgive me if this is a FAQ. I've been spending the entire afternoon with "My Friend, Google", and cannot find an answer that works. To wit:00:09.26 
  Is there a way, using Ghostscript, to convert a file with colored text, to another file with PURELY BLACK text (not, grayscale)?00:10.07 
  The input and output files can be either PDF or PS (I don't care, but ultimately I am given PDFs and want to produce PDFs)00:10.35 
  All the solutions I have found (superuser.com, stackexchange.com, etc) either a) do not work (though they might have worked in previous versions of gs) or b) only create grayscale outputs (which I can do by myself already).00:12.25 
  I am on Linux, so I cannot use Adobe Acrobat to print out in B&W. My print driver options do not include "text in B&W only".00:12.53 
  I put 3 examples up on my Google Drive00:19.10 
  https://drive.google.com/drive/folders/1IkoOUrTlcvepmqISJZfu9In9p0Ypvvrr?usp=sharing00:19.13 
  If the "color" version is the original PDF, I want something that converts that to the "bw" version PDF, /NOT/ the "gray" version.00:19.51 
artifexirc-bot <Robin_Watts> I believe there may be an option for that, yes. mvrhel is the guy who'd know, and he'll be back monday west coast US time.00:34.57 
  <Robin_Watts> (I think it's come up before, I can't remember whether it was acted on or not, but Michael would know)00:35.24 
  <RayJohnston> I'm not sure what you've tried from stackoverflow, etc., but the "best way" is probably to use an ICC profile that maps everything to 100% black (except near white). An exception for near white is needed because some producers use white text on a white background "underlay" to put 'invisible' text on pages for cut and paste (instead of using PDF textrenderingmode 3). Also white text on a dark background is probably still desira00:47.40 
  <RayJohnston> I don't know if @mvrhel is still working on this, but I know this has come up before.00:58.31 
androclus Thanks, all (and bot)06:08.35 
  I'll ask @mvrhel on Mon or Tue06:08.52 
  Until then, I'll encapsulate all the answers I found into a single command with variations:06:09.47 
  gs \06:10.21 
  -o "bw.pdf" \06:10.21 
  -sDEVICE=pdfwrite \06:10.21 
  -sColorConversionStrategy=Gray \06:10.21 
  #-sColorConversionStrategy=Mono \06:10.24 
  -dProcessColorModel=/DeviceGray \06:10.27 
  # -c "/osetcolor {setcolor} bind def /setcolor {pop [0 0 0] osetcolor} def" \06:10.31 
  # -c "/setrgbcolor {pop pop pop 0 setgray} bind def" \06:10.34 
  -dCompatibilityLevel=1.4 \06:10.37 
  -dNOPAUSE \06:10.40 
  -dBATCH \06:10.43 
  -f "${1}"06:10.46 
  06:10.49 
  These are all the things I have tried in various combinations (permutations?)06:10.54 
  These days the -c commands appear to get completely ignored, as well06:11.26 
  And I don't understand RayJohnston's answer about setting an ICC profile because I don't know how to do that, but I can certainly research it.06:12.13 
  But off the cuff, it certainly seems to me that this has been asked enough times on the 'net that, it would be lovely if there were just a single-parameter option that just, "Ma[d]e it So, #1!" :-) rather than having to do anything complicated. But, of course, we always want our own use-case to get #1 priority ;-) so I get it..06:14.07 
artifexirc-bot <RayJohnston> well, just offhand in a script that has a '#', everything following is ignored (comment)06:21.08 
  <RayJohnston> so that covers your '-c' options06:21.33 
  <RayJohnston> and the -c options should be LAST, just before the -f because /some/ options have to precede the -c06:22.08 
  <RayJohnston> that is a MAJOR pain with Ghostscript command line options, so -c as the last thing before -f is the only approach to avoid gs_init.ps interactions.06:24.01 
  <RayJohnston> and note that -c "/osetcolor {setcolor} bind def /setcolor {pop [0 0 0] osetcolor} def" is problematic since 'setcolor' expects a number of operands according to the current colorspace. If the current colorspace is RGB (or another additive 3-component colorspace) then that works, but WILL set white (e.g. 1 1 1 setcolor to black).06:27.18 
  <RayJohnston> and note that -c "/osetcolor {setcolor} bind def /setcolor {pop [0 0 0] osetcolor} def" is problematic since 'setcolor' expects a number of operands according to the current colorspace. If the current colorspace is RGB (or another additive 3-component colorspace) then that works, but WILL set white (e.g. 1 1 1 setcolor )to black.06:27.28 
  <RayJohnston> and setcolor is not the only operator to set colors. There is setgray, setrgbcolor, setcmykcolor. And if the current colorspace is Indexed, Pattern, DeviceN, or Separation that is EXTREMELY unlikely to work as expected.06:29.43 
  <RayJohnston> that's why I recommend the -sTextICCProfile=____ approach. Now, with pdfwrite, I'm not sure if map text to black is possible using that approach.06:30.52 
  <KenSharp> androclus, the next version of Ghostscript (RC1 is currently available and being tested) will allow the new parameter -dBlackText which (with certain minor caveats) will set text to black. The caveats are; type 3 fonts won't be affected (because thse can contain, literally, anything) and text which isn't text (linework, images) won't be affected either.11:03.54 
  <KenSharp> The TextICCProfile will have no effect on pdfwrite output.11:04.27 
  <KenSharp> When the input is a PDF fiel you can't redefine the PostScript operators (or at least not easily) because these are bound in the PDF interpreter before the interpreter starts up.11:05.18 
  <KenSharp> So fundamentally, you cannot do this in any simple fashion with pdfwrite and versions of Ghostscript prior to 9.54.011:05.43 
 <<<Back 1 day (to 2021/03/20)Forward 1 day (to 2021/03/22)>>> 
ghostscript.com #mupdf
Search: