Convert sRGB PDF to CMYK PDF - pdf

How can I convert sRGB PDF to CMYK PDF on Linux Command Line, by keeping small file sizes and high qualtiy.
If I use imagemagic convert, I get the correct colors with this command.:
convert -profile /usr/share/ghostscript/9.05/iccprofiles/srgb.icc -profile /usr/share/ghostscript/9.05/iccprofiles/default_cmyk.icc sRGB.pdf default_cmyk.pdf
But this does not keep a sharp image. If I use convert qualtiy options to solve this, the file size blow up.
The qualtiy of the image is much better, if I use GhostScript.
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -sOutputICCProle=/usr/share/ghostscript/9.05/iccprofiles/default_cmyk.icc -dOverrideICC -sOutputFile=gs_default_cmyk.pdf sRGB.pdf
But then colors does not fit.
How can I get the colors I get with convert and the line accuracy and file size I get with GhostScript?

Related

ghostscript cmyk export yields wrong black

I'm trying to convert an RGB-pdf file created by Inkscape to a print ready cmyk-pdf using PSOcoated_v3.icc color profile. PDF generation works fine. However, I'd like to check for correct final colors, especially for the black. As I did not found any (free) tool to pick the cmyk color from the final pdf I thought as a first check I convert the RGB-pdf to cmyk-tiff and check the black value. Doing so using
gs -q -dBATCH -dSAFER -dNOPAUSE \
-sDEVICE=tiff32nc \
-sDefaultRGBProfile=sRGB2014.icc \
-dOverrideICC \
-sOutputICCProfile=PSOcoated_v3.icc \
-sProcessColorModel=DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sOutputFile=rgb.pdf \
cmyk.tiff
yields a cmyk black value of [0.83, 0.67, 0.51, 0.95]. Contrarily, when I use libcms2 to convert rgb (0,0,0) to cmyk I get [0.92, 0.64, 0.45, 0.96] which matches (almost) some information about the PSOcoated_v3.icc profile I found here. To confirmed that the source RGB-file black reads (0,0,0) I convert the RGB-pdf to an RGB-tiff and do find the black to be (0,0,0).
Am I missing something in the command of might this be a gs bug?
If I take an RGB color of [0,0,0] in sRGB color space and convert it to the CMYK value defined by the PSO coated v3 ICC profile in Photoshop (using Adobe ACE CMM in Photoshop), I get exactly the CMYK values you are seeing with gs, that is [0.83, 0.67, 0.51, 0.95].
That was using a relative colorimetric rendering intent with black point compensation enabled. Those are the settings that gs would be using for lcms by default.
I suspect that when you use libcms2, it is using a different rendering intent. For example, when I use the perceptual rendering intent with Adobe ACE I get [0.90, 0.64, 0.45, 0.96].
Note that you can specify with gs what rendering intent you want to use with
-dRenderIntent=0/1/2/3 . See https://ghostscript.com/doc/current/Use.htm#ICC_color_parameters for details.

How to limit PDF rasterization size when using ImageMagick/Ghostscript

To convert pdfs/eps to pixel images we use ImageMagick. When converting a PDF the command can look like this:
convert -verbose -density 150 -trim -colorspace sRGB input.pdf -quality 90 -flatten -sharpen 0x1.0 output.png
However, the input PDF (which contains only a few paths) has a specified size of 300cm by 200cm, and Ghostscript doesn't like this, and creates a huge png. The verbose output of imagemagick shows this:
"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r150x150" "-sOutputFile=/tmp/magick-3036AW7mUOP25w7J%d" "-f/tmp/magick-3036PxgJinljqMwV" "-f/tmp/magick-30369hcErAROr7V6"
/tmp/magick-3036AW7mUOP25w7J1 PNG 17717x11811 17717x11811+0+0 8-bit sRGB 1.003MB 3.910u 0:03.929
input.pdf PNG 17717x11811 17717x11811+0+0 16-bit sRGB 1.003MB 0.000u 0:00.000
PNG 17717x11811. Huge. I only need a 256x256 image.
I have tried the geometry (-geometry 256x256) options and the density option (before the filename, -density 150) in different configurations, but I does not change the ghostscript output, for example:
convert -verbose -density 150 -trim -geometry 265x265 -colorspace sRGB input.pdf -quality 90 output.png
"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r150x150" "-sOutputFile=/tmp/magick-3233p3ofct0fiy5T%d" "-f/tmp/magick-3233Rads_vSSpKa6" "-f/tmp/magick-3233LQMrrEFgT0fi"
/tmp/magick-3233p3ofct0fiy5T1 PNG 17717x11811 17717x11811+0+0 8-bit sRGB 1.003MB 3.800u 0:03.799
input.pdf PNG 17717x11811 17717x11811+0+0 16-bit sRGB 1.003MB 0.000u 0:00.000
input.pdf=>output.png PNG 17717x11811=>265x38 321x213+28+65 16-bit sRGB 7.96KB 1.080u 0:00.559
How can you define the constraints for Ghostscript, when using ImageMagick?
I wouldn't say 'Ghostscript doesn't like this', if the media size is huge, then of course Ghostscript creates a huge PNG, what else did you expect it to do ?
300 cm is 118.11 inches, which at 150 dpi works out at a bitmap 17716.5, or rounded up to 17717 pixels.
200 cm is 78.74 inches, at 150 dpi that works out to 11811 pixels.
If you want it at a lower resolution, then alter the setting of -r ('density' in ImageMagick). For example, you could set 'density 10', presumably that would produce a file 1181x787. To get 256x256 you would need to set the resolution to ~2 dpi. You may, of course, find that its rather hard to see any detail when the result is that coarse.
Alternatively you can tell Ghostscript the size of media you want, and tell it 'FIXEDMEDIA' so it doesn't alter according to requests from the PostScript program or PDF file.
-g sets the media dimensions in pixels, and -dFIXEDMEDIA tells Ghostscript that the media is fixed. You will almost certainly want to also set -dFitPage, or you will only get a tiny portion of the bottom left hand corner. You will also need to not set -r.
-dFIXEDMEDIA -g and -r are described in use.htm in the ghostscript documentation
Depending on the age of your Ghostscript installation you may not be able to use -dFitPage but you might have to use -dPDFFitPage.
Almost certainly you will want to do this from the command line using Ghostscript instead of ImageMagick, I imagine constructing the command line in IM would be difficult.

Ghostscript - Wrong CMYK Color Conversion - 100% Yellow convert to 98% Yellow?

I try to convert a CMYK .pdf as CMYK .tif with the good CMYK percentages.
But i've a strange color conversion.
Colors:
Look some converted color to understand the "strange" conversion:
100% yellow in pdf was converted as 98% yellow the TIF:
PDF = C:0 M:0 Y:100 K:0
TIF = C:0 M:0 Y:98 K:0
100% Magenta in pdf was converted as 1C/100M/1Y the TIF:
PDF = C:0 M:100 Y:0 K:0
TIF = C:1 M:100 Y:1 K:0
black is good (and all gray tone like 10%,20%...):
PDF = C:0 M:0 Y:0 K:100
TIF = C:0 M:0 Y:0 K:100
but full 100 is not good !?:
PDF = C:100 M:100 Y:100 K:100
TIF = C:73 M:68 Y:66 K:89
and a C100/M20 wrong too (pdf total 120 tif total 121 ?):
PDF = C:100 M:20 Y:0 K:0
TIF = C:99 M:21 Y:1 K:0
files:
download the source PDF:
[https://drive.google.com/file/d/0Byc9qwtxxi1dSlo2eHJxM1hpMU0/view?usp=sharing][1]
download the converted TIF:
[https://drive.google.com/file/d/0Byc9qwtxxi1dVWN6NWlBUEF0Z2c/view?usp=sharing][2]
!!!Attention: Open the files in photoshop to correctly preview the
color and use the color picker to compare the value of each colors.
Cmd:
I search on google and read all the ghostscript doc since 2 weeks, and that's my best cmd :
gs -dNOPAUSE -dBATCH -dSAFER
-sDEVICE=tiff32nc
-sDeviceNProfile
-dKPreserve=2
-dRenderIntent=1
-dCOLORSCREEN=false
-dNOINTERPOLATE
-dUseCIEColor
-dNOTRANSPARENCY
-dGraphicsAlphaBits=4
-dTextAlphaBits=4
-dFirstPage=1
-dLastPage=1
-r600
-sOutputICCProfile=USwebCoatedSOWPv2.icc
-sOutputFile=CMYK.tif
CMYK.pdf
(Unix Ghostscript 9.10)
Doc:
http://www.ghostscript.com/doc/9.10/GS9_Color_Management.pdf
http://ghostscript.com/doc/current/Devices.htm#PDF
???
What do you think ? is a bug or a wrong cmd !?
Did anyone else have this experience?
Thanks,
UPDATE 1
I reduce the cmd at his minimal :
gs -dNOPAUSE -dBATCH -dSAFER
-sDEVICE=tiffsep
-dKPreserve=2
-sOutputFile=CMYK.tif
-r300
-dGraphicsAlphaBits=4
-dTextAlphaBits=4
-dFirstPage=1
-dLastPage=1
CMYK.pdf
And have the same wrong color convertion.
For me, the ICC profile can't change color percents... a 100% Yellow is a 100% Yellow ! not agree?
(in all cases, we have the same issue with or without icc profile)
UPDATE 2
At the beginning, i can't reproduce the colors "bug" in photoshop, I thought it was ghostscript.
But i found the difference between "assign" and "convert" icc profile in photoshop.
photoshop "assign" screencast : http://quick.as/r2jrTn4zw
photoshop "convert" screencast : http://quick.as/xQzaHZ9xp
And it is not a bug !
New issue
Can't we not use the icc profile when we convert a PDF to TIF ? or use
globally the same profile to cancel the convert effect ?
First, update to the current shipping version of Ghostscript. If you still think you see a problem, then open a bug report at httpss://bugs.ghostscript.com
If you open a bug please be sure to attach the specimen file, and give a complete (as simple as possible) command line to reproduce the problem. If you are using an ICC profile, you'll need to supply that as well.
By the way, I think you have a typo there as well '-sOutputICCProfile=USwebCoatedSOWPv2.icc'
Oh, and if you are intending to get decent colour management, under no circumstances should you be setting -dUseCIEColor.
I'm not clear on what you expect the CMYK values to be when you are using an ICC Profile to correct the output, you surely aren't expecting them to be unchanged ?
I'm so close... with this tiny poorly documented option: -dNOSUBSTDEVICECOLORS
gs -sDEVICE=tiff 32nc -dNOSUBSTDEVICECOLORS -sOutputFile=CMYK.tif
CMYK.pdf
In all of my test, the most uncatchable was the C100M100Y100K100... now is good like M100, K100, K50, M100C20, ... ! But only the Cyan100 and Yellow100 turn again on 99% !!!
I'll get it... on next...

How to create CMYK color seperation combinations using GhostScript

I created color separations using
gs -sDEVICE=tiffsep -dNOPAUSE -dBATCH -dSAFER -r600x600 -sOutputFile=p%08d.tif input.pdf
The outputs are all greyscale separations as documented.
Questions
1. How do I combine just the CYAN and MAGENTA separations (or any combination of colors) to make a PDF file?
2. How do I make sure the output PDF from the combo is in color and not greyscale?
Thanks.
You should be able to use Imagemagick's convert to combine CMYK separations; references:
http://www.productionmonkeys.net/guides/ghostscript/examples
CMYK colors inverted with draw or annotate - ImageMagick forum
Combine 4 grayscale images into a final CMYK image - ImageMagick
Example: first, create RGB pdf with Latex (from https://softwarerecs.stackexchange.com/questions/19210/linux-gui-for-quick-browsing-of-cmyk-separations-of-multi-page-pdf); use this as test.tex:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=none,draw=black,line width=2pt] (0cm,0cm) rectangle (4cm,5cm);
\draw[fill=red] (1cm,1cm) circle (1cm) ;
\draw[fill=blue] (2cm,2.5cm) circle (1cm) ;
\draw[fill=green] (3cm,4cm) circle (1cm) ;
\end{tikzpicture}
\end{document}
... then build the PDF with:
pdflatex test.tex
Split RGB pdf into CMYK separations as tiff images using Ghostscript (see original softwarerecs thread for images), which will be called:
gs -sDEVICE=tiffsep -dNOPAUSE -dBATCH -dSAFER -r150x150 -sOutputFile=test%04d.tif test.pdf
Merge/combine CMYK separations into a CMYK color tiff using Imagemagick:
convert \
test0001\(Cyan\).tif \
test0001\(Magenta\).tif \
test0001\(Yellow\).tif \
test0001\(Black\).tif \
-set colorspace CMYK -negate -combine combined.tif
... and here is how the final combined.tif looks like (I had to do convert combined.tif combined.png to upload it here, else .tif alone is not accepted):
For comparison, here is a png derived from the original PDF (convert -density 150 -flatten test.pdf test.png):
Notice how the colors are slightly different, which is expected due to the colorspace roundtrip. Also, note that for more correct colors, you'll probably have to use ICC profiles during conversion...
Finally, you should find a way to convert/import the final CMYK color TIFF into a PDF... (probably either ghostscript or imagemagick could do that, but I haven't tried it..)
For just cyan and magenta - use a white image with the same size as the channel TIF separations, to insert it in place of the missing separations:
convert -size 240x299 xc:white white.png
... and then do the merge again:
convert \
test0001\(Cyan\).tif \
test0001\(Magenta\).tif \
white.png \
white.png \
-set colorspace CMYK -negate -combine combinedCM.tif
Here is the output (after convert combinedCM.tif combinedCM.png):
Open the separations in an image editor which supports CMYK channels (eg Photoshop), combine the channels as required, save as PDF (or PostScript and use GS to convert to PDF).

Convert PDF to CMYK but ignore black?

I am converting an RGB PDF to CMYK using the following command:
/usr/local/bin/gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK -sColorConversionStrategyForImages=CMYK \
-dProcessColorModel=/DeviceCMYK -dEncodeColorImages=false \
-dEncodeGrayImages=false -dEncodeMonoImages=false -sOutputFile=CMYK.PDF RGB.PDF
The resulting file is 100% CMYK, however anything that was 100% black in the RGB PDF is now:
C: 72%
M: 68%
Y: 67%
K: 89%
The result is that black is a slightly dark grey when really it should be black.
Is there anything I need to add to this command to ensure black remains as black during the conversion?
With the current version of pdfwrite you are restricted to the colour conversions in the software, and there is nothign you can do about this.
The colour management is undergoing serious revision, and the next release should make it possible to deal with this.
Examples of Ghostscript commands to convert PDF from sRGB or eciRGB_v2 to eciCMYK_v2 (FOGRA 59) while keeping black plain (K only), not rich (CMYK)
I managed to convert PDF file in RGB to CMYK while keeping RGB black #000000 plain K black, not rich CMYK black.
DeviceLink ICC had to be created from e.g. eciRGB_v2 (or sRGB, if your source is sRGB) profile to the appropriate CMYK profile using collink tool (from argyll package) with the "-f" attribute to hack the black colors.
Ghostscript is then called with a control file declaring use of the profile and its parameters.
Example of making the DeviceLink RGB to CMYK profile
collink -v -f eciRGB_v2.icc eciCMYK_v2.icc eciRGB_v2_to_eciCMYK_v2.icc
Example of a control file to map eciRGB_v2 to eciCMYK_v2
Image_RGB eciRGB_v2_to_eciCMYK_v2.icc 0 1 0
Graphic_RGB eciRGB_v2_to_eciCMYK_v2.icc 0 1 0
Text_RGB eciRGB_v2_to_eciCMYK_v2.icc 0 1 0
Sample ghostscript command to do the actual conversion
gs -o 2-output-cmyk-from-eciRGB.pdf \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK \
-sSourceObjectICC=control-eciRGB_v2.txt \
1-input-rgb.pdf