2013-02-27 151 views
1

这涉及到:RGB转换PDF到CMYK保持100%K(黑色)和100%,M(品红),在Linux上

Converting (any) PDF to black (K)-only CMYK

请先对不起我的英语。

此相关链接对我的问题有50%的解决方案。 唯一剩下的就是我也需要洋红色是100%洋红色。

这里的情景:

我有这样的HTML:

在/ usr/bin中/ wkhtmltopdf file.html output1.pdf

<font color="magenta">Hello </font> 
<font color="#000000"> World </font> 

1 - 我把它转换

2 - 将黑色文本转换为100%k:

gs \ 
    -dNOPAUSE \ 
    -dBATCH \ 
    -sDEVICE=ps2write \ 
    -sOutputFile=output1.ps \ 
    output1.pdf 

# PS to PDF using replacement function in HackRGB-cmyk-inv.ps 
gs \ 
    -dNOPAUSE \ 
    -dBATCH \ 
    -sDEVICE=pdfwrite \ 
    -sOutputFile=output2.pdf \ 
    /HackRGB-cmyk-inv.ps \ 
    output1.ps 

现在我有一个output2.pdf,黑色文本是100%K,但品红色不是100%M ...

这里是HackRGB-cmyk-ink.ps(postscript)的内容参考:

%! 
/oldsetrgbcolor /setrgbcolor load def 
/setrgbcolor { 
(in replacement setrgbcolor\n) print 
           %% R G B 
    1 index 1 index  %% R G B G B 
    eq {     %% 
    2 index 1 index %% R G B R B 
    eq { 
         %% Here if R = G = B 
     pop pop   %% remove two values 
     % setgray % "replace the 'setgray' with": 
     0 0 0 4 -1 roll % setcmykcolor 
     -1 mul   %% obtain -R on top of stack 
     1 add   %% obtain 1-R on top of stack 
     setcmykcolor %% now set(cmykcolor) K (as 1-R) 
    } { 
     oldsetrgbcolor %% set the RGB values 
    } ifelse 
    }{ 
    oldsetrgbcolor  %% Set the RGB values 
    }ifelse 

} bind def 
/oldsetgray /setgray load def 
/setgray { 
(in replacement setgray\n) print 
    % == % debug: pop last element and print it 
    % here we're at a gray value; 
    % http://www.tailrecursive.org/postscript/operators.html#setcymkcolor 
    % setgray: "gray-value must be a number from 0 (black) to 1 (white)." 
    % setcymkcolor: "The components must be between 0 (none) to 1 (full)." 
    % so convert here again: 
    0 0 0 4 -1 roll % push CMY:000 after Gray and roll down, 
        % so top of stack becomes 
        % ...:C:M:Y:Gray 
    -1 mul   %% obtain -Gray on top of stack 
    1 add   %% obtain 1-Gray on top of stack 
    setcmykcolor %% now set(cmykcolor) K (as 1-Gray) 
} bind def 


%~ # test: rgb2gray 
%~ gs -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=./blah-slide-hackRGB-gray.ps ./HackRGB.ps ./blah-slide-gsps2w.ps 
%~ # gray2cmyk 
%~ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=./blah-slide-hackRGB-gray-ci.pdf ./HackRGB-cmyk-inv.ps ./blah-slide-hackRGB-gray.ps 
%~ # check separations - looks OK 
%~ gs -sDEVICE=tiffsep -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1 -dLastPage=1 -sOutputFile=p%02d.tif blah-slide-hackRGB-gray-ci.pdf && eog p01.tif 2>/dev/null 

一些想法如何做到这一点?

问候。

+0

这可能取决于什么在“HackRGB-cmyk-inv.ps – KenS 2013-02-27 16:20:58

+0

是的,现在我正在努力学习后记编辑hackRGB-CMYK油墨.ps 我会把hackRGB-cmyk-ink.ps文件的内容放在这里作为参考 – ricardo 2013-02-27 16:43:00

回答

1

这是对黑客的快速入侵。在oldsetrgbcolor之后,您可以检查cmyk颜色并对其进行修改。也许今晚我可以制作一个更通用的模块,剪下这个将检查50%洋红色并将其改为100%。 (cmyk-) print pstack行将显示找到的cmyk颜色,如果计算的颜色不是.5,就像它可能是.49一样,则可能需要它,所以一旦看到这些值,请删除该行。

}{ 
    oldsetrgbcolor  %% Set the RGB values 
    }ifelse 

}{ 
    oldsetrgbcolor  %% Set the RGB values 
    currentcmykcolor %puts 4 numbers on the stack 
    (cmyk-) print pstack %display the colors (remove when things work correctly) 
    3 -1 roll   %put magenta on top of stack 
    dup     %make copy of magenta value 
    .5     %put magenta test value on stack (then may not be exactly .5, see pstack) 
    eq     %see of magenta is equal to test value (.5) 
    {pop 1}if   %if it is equal, pop off the .5 and put a 1 onto the stack 
    3 1 roll   %put magenta back where it belongs in the stack 
    setcmykcolor  %reset the cmyk to have new magenta value 
    }ifelse 
+0

我认为你需要'3 -1 roll'把品红放在上面,'3 1 roll'放回去。或者你可以使用'4 2卷'。 – 2013-02-27 18:37:55

+0

当然,你的权利!对不起,我的诵读困难正在踢入。谢谢,我会纠正它。 – 2013-02-27 23:40:17

+0

没问题。尽管我自己也这么说,但我有点儿太过分了。 :)对于tricksy的东西,我尝试写在3列:代码%堆栈图片...解释。这就是你可以给所有未命名的堆栈数据命名的地方,并且可以清楚地看到你的所有'roll'和'index's。例如。 xpose程序[here](http://stackoverflow.com/a/14600918/733077) – 2013-02-28 09:12:11