gpt4 book ai didi

linux - Converting PDF to CMYK (with identifying CMYK)

转载 作者:IT王子 更新时间:2023-10-29 00:14:50 27 4
gpt4 key购买 nike

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

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

\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;对于上面的来源:

$ 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,它将被识别为 CMYK identify - 但即使在那里也没有运气:

$ 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
...

因此,唯一被识别视为变化的是Type: Grayscale(来自之前的Type: Palette);但除此之外它仍然看到 RGB 色彩空间!

除此之外,请注意 identify 能够正确报告 CMYK pdf - 参见 CMYK poster example: fitting pdf page size to (bitmap) image size? #17843 - TeX - LaTeX - Stack Exchange有关使用 convertgs 生成此类 PDF 文件的命令行示例。其实我们可以执行:

convert test.pdf -depth 8 -colorspace cmyk -alpha Off test-c.pdf

... 而这生成一个 PDF,该 PDF 将被识别为 CMYK - 然而,PDF 也将被光栅化(默认为 72 dpi)。

编辑:我刚刚发现,如果我在 OpenOffice 中创建一个 .odp 演示文稿,并将其导出为 PDF;该 PDF 默认为 RGB,但是,以下命令(来自 ghostscript Examples | Production Monkeys):

# Color PDF to CMYK:
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK \
-sOutputFile=output.pdf input.pdf

...实际上将生成一个 CMYK pdf,由 identify 报告(尽管黑色会很丰富,而不是纯色 - 在所有四个 channel 上);但是,此命令在幻灯片添加图像时起作用(显然,它是触发颜色转换的图像?!)!有趣的是,我无法从 pdflatex PDF 中获得相同的效果。

所以我想我的问题可以通过两种方式提出:

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

提前感谢您的任何回答,
干杯!

一些引用资料:

最佳答案

sdaau,您尝试将 PDF 转换为 CMYK 时使用的命令不正确。试试这个:

 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 artifacts appearing在图片中(以前没有的地方),添加:

-dEncodeColorImages=false

进入命令行。

(几乎所有 GS PDF->PDF 处理都是如此,不仅仅是这种情况。因为 GS 默认情况下会在询问时创建一个全新的文件,其中包含新构造的对象和新的文件结构生成 PDF 输出——它不会简单地重复使用以前的对象,因为像 pdftk 这样更“愚蠢”的 PDF 处理器确实 {pdftk 还有其他尽管有优点,但不要误解我的说法!。GS 默认应用 JPEG 压缩——查看当前的 Ps2pdf documentation 并搜索 “ColorImageFilter” 了解更多详情...)

关于linux - Converting PDF to CMYK (with identifying CMYK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6241282/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com