首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将PDF转换为CMYK (识别CMYK)

将PDF转换为CMYK (识别CMYK)
EN

Stack Overflow用户
提问于 2011-06-05 06:01:51
回答 5查看 33.1K关注 0票数 31

我很难让ImageMagick的identify识别为CMYK的PDF格式。

本质上,假设我正在构建这个文件,test.tex,使用pdflatex

代码语言:javascript
复制
\documentclass[a4paper,12pt]{article}

%% https://tex.stackexchange.com/questions/13071
\pdfcompresslevel=0

%% http://compgroups.net/comp.text.tex/Making-a-cmyk-PDF
%% ln -s /usr/share/color/icc/sRGB.icm .
% \immediate\pdfobj stream attr{/N 4} file{sRGB.icm}
% \pdfcatalog{%
% /OutputIntents [ <<
% /Type /OutputIntent
% /S/GTS_PDFA1
% /DestOutputProfile \the\pdflastobj\space 0 R
% /OutputConditionIdentifier (sRGB IEC61966-2.1)
% /Info(sRGB IEC61966-2.1)
% >> ]
% }

%% http://latex-my.blogspot.com/2010/02/cmyk-output-for-commercial-printing.html
%% https://tex.stackexchange.com/questions/9961
\usepackage[cmyk]{xcolor}

\begin{document}
Some text here...
\end{document}

然后,如果我试图标识结果的test.pdf文件,我将它作为RGB,不管我尝试了什么选项(至少根据源代码中的链接)-但是,其中的颜色将保存为CMYK;对于上面的源:

代码语言:javascript
复制
$ grep -ia 'cmyk\|rgb\| k' test.pdf 
0 0 0 1 k 0 0 0 1 K
0 0 0 1 k 0 0 0 1 K
0 0 0 1 k 0 0 0 1 K
0 0 0 1 k 0 0 0 1 K
FontDirectory/CMR12 known{/CMR12 findfont dup/UniqueID known{dup
/PTEX.Fullbanner (This is pdfTeX, Version 3.1415926-1.40.11-2.2 (TeX Live 2010) kpathsea version 6.0.0)

$ identify -verbose 'test.pdf[0]'
...
  Type: Palette
  Endianess: Undefined
  Colorspace: RGB
  Depth: 16/8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
...
    Green:
...
    Blue:
...
  Histogram:
         5: (12593,11565,11822) #31312D2D2E2E rgb(49,45,46)
         4: (16448,15420,15677) #40403C3C3D3D rgb(64,60,61)
         9: (20303,19275,19532) #4F4F4B4B4C4C rgb(79,75,76)
        25: (23901,23130,23387) #5D5D5A5A5B5B rgb(93,90,91)
...

如果我也取消了\immediate\pdfobj stream ...部分的注释,也会发生同样的情况;但是,如果文档中只有一种颜色(黑色),那么identify在哪里找出RGB值的直方图(尽管可以说,它们都接近灰色) ?!

因此,没关系,那么我想我最好尝试使用ghostscripttest.pdf转换成一个新的pdf,这将被identify识别为CMYK --但是即使在那里也没有运气:

代码语言:javascript
复制
$ gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite  -sOutputFile=test-gs.pdf -dUseCIEColor -sProcessColorModel=DeviceRGB -dProcessColorModel=/DeviceCMYK -sColorConversionStrategy=/CMYK test.pdf 

GPL Ghostscript 9.01 (2011-02-07)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1


$ identify -verbose 'test-gs.pdf[0]'
...
  Type: Grayscale
  Base type: Grayscale
  Endianess: Undefined
  Colorspace: RGB
  Depth: 16/8-bit
...

因此,identify认为唯一的变化是Type: Grayscale (来自以前的Type: Palette);但除此之外,它仍然看到一个RGB颜色空间!

同时,请注意,identify 是能够正确报告CMYK的-参见CMYK海报示例:将pdf页面大小与(位图)图像大小?#17843 - TeX - LaTeX -堆栈交换获取使用convertgs生成这样一个pdf文件的命令行示例。事实上,我们可以执行:

代码语言:javascript
复制
convert test.pdf -depth 8 -colorspace cmyk -alpha Off test-c.pdf

..。这个将产生一个,它将被identify编辑为CMYK -然而,该PDF也将被光栅化(默认为72 dpi)。

编辑:我刚刚发现,如果我用.odp创建了一个OpenOffice演示文稿,并将其导出为PDF;但是,在默认情况下,该PDF将是RGB,但是,下面的命令(来自幽灵脚本示例?生产猴子):

代码语言:javascript
复制
# Color PDF to CMYK:
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK \
-sOutputFile=output.pdf input.pdf

..。实际上,将产生一个CMYK,由identify这样报告(虽然,黑色将是丰富的,而不是普通的-在所有四个频道);然而,这个命令将只有当幻灯片有一个附加的图像(显然,它是一个触发颜色转换?!)有趣的是,我无法从pdflatex PDF中获得同样的效果。

所以我想我的问题可以用两种方式来问:

  • 在Linux中是否有任何命令行转换方法,将RGB转换为CMYK,同时保留向量,这在identify中是这样的(因此将建立CMYK颜色的正确直方图)。
  • 还有其他类似于identify的命令行Linux工具可以正确识别CMYK颜色的使用,即使在原始的test.pdf中也是如此(并且可能根据任意选择的pdflatex页面构建颜色直方图,就像identify应该做的那样)?

谢谢你的回答,

干杯!

一些参考资料:

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-12-19 21:02:07

sdaau,用于将PDF转换为CMYK的命令是不正确的。试一试这个:

代码语言:javascript
复制
 gs \
   -o test-cmyk.pdf \
   -sDEVICE=pdfwrite \
   -sProcessColorModel=DeviceCMYK \
   -sColorConversionStrategy=CMYK \
   -sColorConversionStrategyForImages=CMYK \
    test.pdf 

更新

如果颜色转换不按需要工作,如果您看到一条“无法将颜色空间转换为灰色,将策略还原为LeaveColorUnchanged”的消息,那么.

  1. 您的Ghostscript可能是9.x版本系列中更新的版本,并且
  2. 源PDF可能使用嵌入的ICC颜色配置文件。

在本例中,将-dOverrideICC添加到命令行,并查看它是否按需要更改结果。

更新2

为了避免图像中的JPEG 伪像 (以前没有),添加:

代码语言:javascript
复制
-dEncodeColorImages=false

进入命令行。

(几乎所有的GS PDF->PDF处理都是这样,而不仅仅是在这种情况下。因为GS默认使用新构造的对象创建一个全新的文件,并在被要求生成PDF输出时创建一个新的文件结构--它不只是简单地重复使用以前的对象,因为像pdftk这样的更“哑”的PDF处理器确实有{__pdftk的其他优点,请不要误解我的声明!}。GS默认应用JPEG压缩--查看当前的Ps2pdf文档并搜索"ColorImageFilter“以了解更多细节.)

票数 31
EN

Stack Overflow用户

发布于 2011-09-14 13:56:40

我有一个无关的问题,但我也在与CMYK PDF目前挣扎。

我在这里写了这个小脚本(叫做pdf2pdfx):

代码语言:javascript
复制
#!/bin/bash

gs \
-dPDFX \
-dBATCH \
-dNOPAUSE \
-dNOOUTERSAVE \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK \
-dProcessColorModel=/DeviceCMYK \
-dPDFSETTINGS=/prepress \
-sOutputFile="${1%%.pdf}_X-3.pdf" \
PDFX_def.ps \
"$1"

我的PDFX_def.ps包含以下内容(我删除了ICC并定义了FOGRA39,这应该是可以的):

代码语言:javascript
复制
%!
% $Id$
% This is a sample prefix file for creating a PDF/X-3 document.
% Feel free to modify entries marked with "Customize".

% This assumes an ICC profile to reside in the file (ISO Coated sb.icc),
% unless the user modifies the corresponding line below.

systemdict /ProcessColorModel known {
  systemdict /ProcessColorModel get dup /DeviceGray ne exch /DeviceCMYK ne and
} {
  true
} ifelse
{ (ERROR: ProcessColorModel must be /DeviceGray or DeviceCMYK.)=
  /ProcessColorModel cvx /rangecheck signalerror
} if

% Define entries to the document Info dictionary :

% /ICCProfile (/usr/share/color/icc/ISOcoated_v2_300_eci.icc) def  % Customize or remove.

[ /GTS_PDFXVersion (PDF/X-3:2002) % Must be so (the standard requires).
  /Title (Title)                  % Customize.
  /Trapped /False                 % Must be so (Ghostscript doesn't provide other).
  /DOCINFO pdfmark

% Define an ICC profile :

currentdict /ICCProfile known {
  [/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
  [{icc_PDFX} <</N systemdict /ProcessColorModel get /DeviceGray eq {1} {4} ifelse >> /PUT pdfmark
  [{icc_PDFX} ICCProfile (r) file /PUT pdfmark
} if

% Define the output intent dictionary :

[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
[{OutputIntent_PDFX} <<
  /Type /OutputIntent              % Must be so (the standard requires).
  /S /GTS_PDFX                     % Must be so (the standard requires).
  /OutputCondition (Commercial and specialty printing) % Customize
  /Info (none)                     % Customize
  /OutputConditionIdentifier (FOGRA39)      % Customize
  /RegistryName (http://www.color.org)   % Must be so (the standard requires).
  currentdict /ICCProfile known {
    /DestOutputProfile {icc_PDFX}  % Must be so (see above).
  } if
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFX} ]>> /PUT pdfmark

标识然后正确报告CMYK颜色空间。在此之前:

代码语言:javascript
复制
tbart@blackknight ~/orpheus/werbung/action $ identify -verbose action_schulungsvideo_v3_print.pdf
Image: action_schulungsvideo_v3_print.pdf
  Format: PDF (Portable Document Format)
  Class: DirectClass
  Geometry: 612x859+0+0
  Resolution: 72x72
  Print size: 8.5x11.9306
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
  Depth: 16/8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 65535 (1)
      mean: 53873.6 (0.822058)
      standard deviation: 19276.7 (0.294144)
      kurtosis: 1.854
      skewness: -1.82565
    Green:
      min: 0 (0)
      max: 65535 (1)
      mean: 55385.6 (0.84513)
      standard deviation: 19274.6 (0.294112)
      kurtosis: 2.09868
      skewness: -1.91651
    Blue:
      min: 0 (0)
      max: 65535 (1)
      mean: 51020 (0.778516)
      standard deviation: 20077.7 (0.306367)
      kurtosis: 0.860627
      skewness: -1.52344
  Image statistics:
    Overall:
      min: 0 (0)
      max: 65535 (1)
      mean: 53426.4 (0.815235)
      standard deviation: 19546.7 (0.298263)
      kurtosis: 1.59453
      skewness: -1.75701
  Rendering intent: Undefined
  Interlace: None
  Background color: white
  Border color: rgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 612x859+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2011-09-14T15:38:57+02:00
    date:modify: 2011-09-14T15:38:57+02:00
    pdf:HiResBoundingBox: 612.283x858.898+0+0
    pdf:Version: PDF-1.5 
    signature: 210bfc9cf90e3b9505385f8b2267da1665b5c2de28bb5223311afba01718bbeb
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 1.577MBB
  Number pixels: 526KB
  Pixels per second: 52.57MB
  User time: 0.020u
  Elapsed time: 0:01.009
  Version: ImageMagick 6.6.5-6 2011-04-08 Q16 http://www.imagemagick.org

之后:

代码语言:javascript
复制
tbart@blackknight ~/orpheus/werbung/action $ pdf2pdfx action_schulungsvideo_v3_print.pdf
GPL Ghostscript 9.04 (2011-08-05)
Copyright (C) 2011 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1


tbart@blackknight ~/orpheus/werbung/action $ identify -verbose action_schulungsvideo_v3_print_X-3.pdf 
Image: action_schulungsvideo_v3_print_X-3.pdf
  Format: PDF (Portable Document Format)
  Class: DirectClass
  Geometry: 612x859+0+0
  Resolution: 72x72
  Print size: 8.5x11.9306
  Units: Undefined
  Type: ColorSeparation
  Base type: ColorSeparation
  Endianess: Undefined
  Colorspace: CMYK
  Depth: 16/8-bit
  Channel depth:
    cyan: 8-bit
    magenta: 8-bit
    yellow: 8-bit
    black: 8-bit
  Channel statistics:
    Cyan:
      min: 0 (0)
      max: 65535 (1)
      mean: 8331.78 (0.127135)
      standard deviation: 14902.2 (0.227392)
      kurtosis: 1.62171
      skewness: 1.7799
    Magenta:
      min: 0 (0)
      max: 62194 (0.94902)
      mean: 6739.34 (0.102836)
      standard deviation: 14517.5 (0.221523)
      kurtosis: 2.08183
      skewness: 1.93276
    Yellow:
      min: 0 (0)
      max: 65535 (1)
      mean: 13310.1 (0.203098)
      standard deviation: 17022.5 (0.259746)
      kurtosis: 0.991135
      skewness: 1.45216
    Black:
      min: 0 (0)
      max: 56540 (0.862745)
      mean: 7117.47 (0.108606)
      standard deviation: 16803.7 (0.256408)
      kurtosis: 3.02752
      skewness: 2.16554
  Image statistics:
    Overall:
      min: 0 (0)
      max: 65535 (1)
      mean: 8874.66 (0.135419)
      standard deviation: 15850.6 (0.241864)
      kurtosis: 2.17614
      skewness: 1.88139
  Total ink density: 292%
  Rendering intent: Undefined
  Interlace: None
  Background color: white
  Border color: cmyk(223,223,223,0)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 612x859+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2011-09-14T15:39:30+02:00
    date:modify: 2011-09-14T15:39:30+02:00
    pdf:HiResBoundingBox: 612.28x858.9+0+0
    pdf:Version: PDF-1.3 
    signature: 0416db7487ea147b974ece5748bc4284e82bfc3fb7cd07a4de050421ba112076
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 2.103MBB
  Number pixels: 526KB
  Pixels per second: 5.25708PB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.6.5-6 2011-04-08 Q16 http://www.imagemagick.org

这是64位Gentoo的gs 9.04,也许这有帮助吗?

源PDF来源于inkscape pdf导出,颜色仅限于在ECI涂层v2中覆盖的颜色。我使用这作为一个解决办法,缺乏CMYK导出的inkscape和缺乏印前准备PDF/X输出.

票数 6
EN

Stack Overflow用户

发布于 2014-08-08 03:06:35

我也被这逼疯了。我确实尝试了@tbart的例子,但它只适用于一些输入pdfs (似乎已经包含了图像,rgb?),而其他的则不行。具体来说,让我们以这个超级简单的ps文件为例:

代码语言:javascript
复制
%!PS
/Times-Roman findfont 30 scalefont setfont
72 680 moveto
0.81 0.72 0 0 setcmykcolor
(This is text!) show
showpage

如果我调用这个test1.ps,然后运行这个命令(在windows上,gs 9.14):

代码语言:javascript
复制
gswin64c -dEmbedAllFonts=true -dPDFX -dBATCH -dNOPAUSE -dNOOUTERSAVE -sDEVICE=pdfwrite -dProcessColorModel=/DeviceCMYK -sOutputICCProfile=CoatedGRACoL2006.icc   -sColorConversionStrategy=CMYK -sColorConversionStrategyForImages=CMYK -sOutputFile=test1.pdf PDFX_def.ps test1.ps

如果你在linux/cygwin上,用gs代替gswin64c。

我使用的CMYK位于PDFX_def.ps和上面的命令中。你可以从这里得到它,但它只是一个随机的ICC,穆奥想要他们的牌,这似乎没有什么特别:http://www.adobe.com/support/downloads/thankyou.jsp?ftpID=4075&fileID=3790

这个输出的test1.pdf在Illustrator中以CMYK的形式加载,但是标识-verbose表示它是sRGB。如果我做了@sdaau的tiffsep事情,它会写出分离,它们有正确的值。

所以我不知道。

有人能让这个ps文件转换成一个CMYK来识别识别吗?

克里斯

编辑:哇。我可能已经想出办法解决了。看起来,in只是在PDF文件中寻找一个/ColorSpace /DeviceCMYK,所以如果我黑了PDFX_def.ps输出它,in就会叫它CMYK。因此,通过查看工作的pdfs,我发现如果这一行的标识有效,而如果没有,则错误地将它们标记为sRGB。

在PDFX_def.ps的末尾,添加/ColorSpace /DeviceCMYK行:

代码语言:javascript
复制
[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
[{OutputIntent_PDFX} <<
  /ColorSpace /DeviceCMYK          % convince ImageMagick's identify that it's CMYK
  /Type /OutputIntent              % Must be so (the standard requires).
  /S /GTS_PDFX                     % Must be so (the standard requires).
  /OutputCondition (Commercial and specialty printing) % Customize
  /Info (none)                     % Customize
  /OutputConditionIdentifier (CGATS TR 003)      % Customize
  /RegistryName (http://www.color.org)   % Must be so (the standard requires).
  currentdict /ICCProfile known {
    /DestOutputProfile {icc_PDFX}  % Must be so (see above).
  } if
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFX} ]>> /PUT pdfmark

轰隆隆。我希望这不会有什么奇怪的兼容性什么的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6241282

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档