如何使用后记插入CMYK图像到PDF



我刚刚开始学习postscript,我已经开始创建PDF(应该是CMYK格式)并插入图像。

然而,我已经搜索和搜索互联网并下载了尽可能多的Postscript手册,而没有这样做的一个简单的例子(请纠正我,如果我错过了任何)。

所以,我的问题是,我有一个CMYK图像,我想把它嵌入到我的PDF。然而,当我使用基于RGB图像的简单示例插入它时,图片结果为负(我已经改变了我认为适合CMYK图像的内容)

下面是我创建的pdf文件

    %!
/Times-Roman findfont 14 scalefont setfont 
<< /PageSize [419.528 595.276] >> setpagedevice 
% MM to Units 
% [ W x H ] 
/DeviceCMYK setcolorspace 
% Page 1 
%
% Set the Original to be the top left
%
0 595.276 translate 
1 -1 scale 
gsave 
%
% Save this state before moving x y specifically for images
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Image 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % set the X and Y of the mask here
-8.5039 140.21007874 translate  %Top Left Coordinates of mask
/box {
   newpath
   moveto
   436.535433071 0 rlineto % width of the mask
   0 463.569448819 rlineto % height of the mask  %Top Left Coordinates
   -436.535433071 0 rlineto
   closepath
} def
0 0 box                % Set up our box
  clip                     % Clip to the box
% DO NOT reset the document to original position 
% as we want the translate to be relative to the clipped box
%
%grestore  * Do not use here
%gsave * Do not use here
%
%% Images when flipped to draw correctly are scaled UPWARDS 
%% so you need to move the x,y position to the bottom left
-1.44 621.714330709 translate % Bottom Left Cordinates
% unset the mirror or the image will be flipped!
1 -1 scale 
% scale the image
438.000944882 657.119055118 scale  %%% Need to work out size and width into Units
1825                   % number of columns per row  %width of the image %%%% IN PIXELS!
2738                   % number of rows %height of the images %%%% IN PIXELS!
8                    % bits per color channel (1, 2, 4, or 8)
[1825 0 0 -2738 0 2738]       % transform array... maps unit square to pixel
(cmyk_image.jpg) (r) file /DCTDecode filter % opens the file and filters the image data
false                 % pull channels from separate sources
4
colorimage
%%%%%
% End of Image 1
%%%%%
showpage

我试过看viewjpeg.ps,但我想有图像插入到PS,而不是通过命令行插入。

多谢

编辑:有问题的图像:)(它是通过wetransfer由于它的大小和cmyk色彩空间)

cmyk_image.jpg

编辑:

我再次调整了代码,使用字典(基于您的帖子KenS简单图像字典)。

    << /PageSize [419.528 595.276] >> setpagedevice 
0 595.276 translate 
1 -1 scale 
-1.44 621.714330709 translate % Bottom Left Cordinates
% unset the mirror or the image will be flipped!
1 -1 scale 
% scale the image
438.000944882 657.119055118 scale  %%% Need to work out size and width into Units
/OneComponentString (cmyk_image.jpg) (r) file /DCTDecode filter  def
/OneComponentImage1
{
<<
/ImageType 1
/Width 1825
/Height 2738
/ImageMatrix [1825 0 0 -2738 0 2738]
/BitsPerComponent 8
/DataSource OneComponentString
>>
} bind def
gsave
/DeviceCMYK setcolorspace
OneComponentImage1 image
grestore
showpage

然而,它仍然是负的(我已经明确地从字典中省略了/Decode[0 1],因为这会抛出以下错误:

    Error: /rangecheck in --image--
Operand stack:
   --dict:7/7(L)--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1951   1   3   %oparray_pop   1950   1   3   %oparray_pop   1934   1   3   %oparray_pop   1820   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   1847   1   3   %oparray_pop
Dictionary stack:
   --dict:1183/1684(ro)(G)--   --dict:0/20(G)--   --dict:80/200(L)--
Current allocation mode is local
Last OS error: Invalid argument

所以,我想我更接近了。有人可以解释解码选项,为什么它可能抛出一个错误时使用CMYK图像?

许多谢谢。

你还没有说你在用哪本手册,所以很难推荐别人。

我要注意的第一件事是,你正在使用colorimage,你可能想要停止这样做,并使用字典形式的图像操作符代替,这是更灵活的。此外,如果您想尝试一些其他图像类型,其中只有具有字典形式,它将更有用。colorimage操作符基本上是第1级和第2级PostScript之间的一个讨厌的hack。

viewjpeg.ps是否与您的JPEG文件正确工作?如果是这样,那么你可以将其用作模板(注意viewjpeg.ps使用图像操作符的字典形式)。

顺便说一下,如果你打算使用JPEG作为你的图像数据源,你会想要小心pdfwrite设置,如果你不改变ColorImageFilter,那么pdfwrite将对你的图像采样应用JPEG压缩。用JPEG压缩以前用JPEG压缩的数据会导致明显的质量损失。

就反转而言,我猜从JPEG图像返回的样本只是相对于PostScript CMYK颜色模型(0 = 0%着色剂,255 = 100%着色剂)进行反转。显然,如果没有看到jpeg文件,我是看不出来的。

多亏了KenS,我能够以300 DPI获得CYMK图像。

    << /PageSize [419.528 595.276] >> setpagedevice 
    % [ W x H ] 
    /DeviceCMYK setcolorspace 
    % Page 1 
    %
    % Set the Original to be the top left
    %
    0 595.276 translate 
    1 -1 scale 
    gsave 

    %% Images when flipped to draw correctly are scaled UPWARDS 
%% so you need to move the x,y position to the bottom left
-1.44 621.714330709 translate % Bottom Left Cordinates
% unset the mirror or the image will be flipped!
1 -1 scale 
% scale the image
438.000944882 657.119055118 scale  %%% Need to work out size and width into Units

/Image1File (cmyk_image.jpg) (r) file /DCTDecode filter  def
/Image1
{
<<
  /ImageType 1
  /Width 1825
  /Height 2738
  /ImageMatrix [1825 0 0 -2738 0 2738]
  /BitsPerComponent 8
  /Decode [1 0 1 0 1 0 1 0] % can either be 1 0 or 0 1
  /DataSource Image1File
>>
} bind def
/DeviceCMYK setcolorspace
Image1 image
% Reset to previous X and Y ( line 13 )
grestore 
gsave
showpage 

然后从命令行执行。

gs -o output.pdf -sDEVICE=pdfwrite -dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false input.ps

最新更新