可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to convert to grayscale this PDF: https://dl.dropboxusercontent.com/u/10351891/page-27.pdf
Ghostscript (v 9.10) with pdfwrite Device fails with a "Unable to convert color space to Gray, reverting strategy to LeaveColorUnchanged." message.
I'm able to convert it through an intermediary ps file (using gs, pdftops (v 0.24.3) or pdf2ps) but this convertion rasterize the whole PDF. I tryed a lot of other things: normalize the PDF using qpdf (v 5.0.1) or pdftk (v 1.44), transform it to a svg file and back to a PDF via Inkscape (v 0.48.4)... nothing seems to work.
The only one solution I found (which is not suitable for me in production environment) is to use Preview on my Mac and apply a Quartz Gray Tone filter manually or with an Automator script.
Anyone find another working way to do it? Or is it possible to normalize the PDF or fix the issue to prevent the Ghostscript message "Unable to convert color space..." or to force the color space in another way?
Thanks!
回答1:
gs \ -sDEVICE=pdfwrite \ -sProcessColorModel=DeviceGray \ -sColorConversionStrategy=Gray \ -dOverrideICC \ -o out.pdf \ -f page-27.pdf
This command converts your file to grayscale (GS 9.10).
回答2:
A bit late in the day, but the top answer doesn't work for me with a different file. The underlying problem appears to be old code in Ghostscript, for which there is a later version that is not enabled by default. More on that here: http://bugs.ghostscript.com/show_bug.cgi?id=694608
The page above also gives a command that works for me:
gs -sDEVICE=pdfwrite -dProcessColorModel=/DeviceGray -dColorConversionStrategy=/Gray -dPDFUseOldCMS=false -o out.pdf -f in.pdf
回答3:
Use the most recent code (not yet released) and set ColorConversionStrategy=Gray
回答4:
If you crack into the file, you'll find that most of the colors are determined through an RGB ICC based color space (look for 8 0 R to find all the references to this colorspace). Perhaps gs is complaining about that?
Who knows.
The take away is that converting a page from one colorspace to another without affecting the content is non-trivial in that you need to be able to render the page and trap all changes to the current color/colorspace and substitute an equivalent in the target space as well as convert all image XObjects in the wrong colorspace, which will require decoding the image data and re-encoding it in the target space, as well as all form XObjects, which will be a task similar to trying to convert the parent page since form XObjects (I think your doc has 4) also contain resources and a content stream of page marking operators (which may include more XObjects).
It's certainly doable, but the process is nearly the same as rendering but with some fairly special-purpose code.
回答5:
very late response, but the following command should work :
convert -colorspace GRAY input.pdf input_gray.pdf
回答6:
In Linux:
Install pdftk
apt-get install pdftk
Once you have installed pdftk, save the script as graypdf.sh with the following code
give the file excecution permissions
chmod +x greypdf.sh
And execute it like this:
./greypdf.sh input.pdf
It will create a file input-gray.pdf in the same location than the initial file
回答7:
You can use something which I created. It gives you the option to choose the specific page numbers that you want to convert to grayscale. Handy if you don't want to grayscale the entire pdf. https://github.com/shoaibkhan94/PdfGrayscaler.