【问题标题】:Convert RGB PDF to CMYK keep 100% K (black) AND 100% M(Magenta) on linux将 RGB PDF 转换为 CMYK 在 Linux 上保持 100% K(黑色)和 100% M(洋红色)
【发布时间】:2013-02-27 15:34:17
【问题描述】:

这与:

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

首先请原谅我的英语。

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

这里的场景:

我有一个这样的html:

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

1- 我将其转换为:

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

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

关于如何做的一些想法?

问候。

【问题讨论】:

  • 这可能取决于 'HackRGB-cmyk-inv.ps 中的内容
  • 是的,我现在正在尝试学习 postscript 来编辑 hackRGB-cmyk-ink.ps 我将把 hackRGB-cmyk-ink.ps 文件的内容放在这里以供参考
  • 小事:“-1 mul”更优雅地作为“neg”完成。所以“neg 1 add”或者,对于另外一个字符,“1 exch sub”。答案将是相同的,即使 PostScript 的数字精度只是单一的,正如我的 Distiller 通过“(Start)= 32768 {rand 2147483647.0 div dup 1 exch sub exch neg 1 add eq {pop} {=} ifelse}重复(完成)=”。

标签: linux pdf postscript cmyk


【解决方案1】:

这里有一个快速破解的方法。在 oldsetrgbcolor 之后,您可以检查 cmyk 颜色并对其进行修改。也许今晚我可以制作一个更通用的模块,剪掉它会检查 50% 的洋红色并将其更改为 100%。 (cmyk-) print pstack 行将显示找到的 cmyk 颜色,如果计算出的颜色不完全是 0.5,您可能需要它,比如它可能是 0.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

【讨论】:

  • 我认为您需要3 -1 roll 将洋红色放在上面,然后3 1 roll 将它放回去。或者你可以同时使用4 2 roll
  • 当,你的权利!抱歉,我的阅读障碍开始了。谢谢,我会纠正它。
  • 没问题。我是一个堆栈奇才,虽然我自己也这么说。 :) 对于棘手的东西,我尝试写成 3 列:code % stack-picture ...说明。在这里,您可以为所有未命名的堆栈数据命名,并(明显地)数出您所有的rolls 和indexes。例如。 xpose 程序here
  • 是的,您肯定已经完成了堆栈练习!但是让我鼓励你,评论你的代码!!!!对于执行如此复杂功能的代码,如果您希望除您之外的其他人理解它,您确实需要在每个函数上放置 cmets,描述函数的用途以及输入和输出。对各种字典及其内容进行描述也很好。除此之外,非常酷!!!!!!
  • 谢谢你们!你们是英雄!
猜你喜欢
  • 2011-09-09
  • 2020-01-23
  • 2022-08-15
  • 1970-01-01
  • 2014-03-12
  • 2011-01-26
  • 2016-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多