【问题标题】:How to insert CMYK image into PDF using postscript如何使用 postscript 将 CMYK 图像插入 PDF
【发布时间】:2015-08-01 21:24:24
【问题描述】:

我刚刚开始学习 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,而不是通过命令行插入。

非常感谢

已编辑:有问题的图像 :)(由于其大小和 cmyk 颜色空间,它是通过 wetransfer 实现的)

cmyk_image.jpg

再次编辑:

我使用字典再次调整了代码(基于您的帖子 KenS Simple Image Dictionary)。

    << /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 图像时可能会引发错误吗?

非常感谢。

【问题讨论】:

    标签: pdf ghostscript postscript cmyk


    【解决方案1】:

    你实际上并没有说你正在使用哪些手册,所以很难推荐其他人。

    我要注意的第一件事是您正在使用 colorimage,您可能希望停止这样做并改用图像运算符的字典形式,这更加灵活。如果您想尝试其他一些具有字典形式的图像类型,它也会更有用。 colorimage 运算符基本上是从 1 级和 2 级 PostScript 之间的日子以来的讨厌黑客。

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

    顺便说一句,如果您计划使用 JPEG 作为图像数据源,您需要注意 pdfwrite 设置,如果您不更改 ColorImageFilter,那么 pdfwrite 将对您的采样图像应用 JPEG 压缩。 JPEG 压缩先前已被 JPEG 压缩的数据会导致质量明显下降。

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

    【讨论】:

    【解决方案2】:

    感谢 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 2017-05-07
      • 2019-12-03
      • 2016-07-19
      • 1970-01-01
      相关资源
      最近更新 更多