2015-05-20 59 views
0

我剛剛開始學習postscript,並且我一直在創建PDF(應該在CMYK中)並插入圖像。如何使用postscript將CMYK圖像插入到PDF中

但是,我搜索並搜索了互聯網,並下載了儘可能多的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 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 

但是它仍然快到了負(我explicily leftout的/解碼[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圖像時可能拋出了一個錯誤?

非常感謝。

回答

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文件就說不清楚。

+0

嗨肯,謝謝你的迴應。 我有的手冊是: https://www.adobe.com/products/postscript/pdfs/PLRM.pdf http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF https: //staff.science.uva.nl/ajpheck/Courses/Mastercourse2005/tutorial.pdf 如果你有更多的指針,那將是驚人的! 是的viewjpeg確實工作 - 我認爲我的問題是我發現很難簡化該腳本。 感謝關於壓縮的提示 - scipt需要記住高分辨率圖像(300 dpi)。 我會看看我是否可以向你提供我所指的圖像。 – MissAran

+0

紅色和藍色書籍是一個很好的起點,如果你打算對字體做任何事情(但它絕對不是必需的),你可能會喜歡看黑白書。如果您打算使用PDF,那麼PDF參考或其ISO版本是值得的。另外,不是手冊而是推薦,請看看Acumen Training的網站和Acumen Journal。 PostScript和PDF的絕佳資源。 http://www.acumentraining.com/acumenjournal.html – KenS

0

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