跳轉到內容

PostScript 常見問題解答/使用 Ghostscript

來自華夏公益教科書,開放的書籍,開放的世界

使用 Ghostscript

[編輯 | 編輯原始碼]

什麼是 Ghostscript 以及在哪裡可以獲取它?

[編輯 | 編輯原始碼]

Ghostscript 是一個常用的開源軟體套件,它基於 Adobe Systems 的頁面描述語言 PostScript 和其 Portable Document Format (PDF) 的 直譯器。該套件由 Artifex Software 和全球社群開發,主要用於文件頁面的光柵化和渲染以顯示或列印它們,以及 PostScript 和 PDF 之間的轉換。它包含一組免費的 PostScript 字型,並在許多第三方應用程式和 GUI 中使用。

有關詳細資訊和軟體下載,請參見 Ghostscript

如何建立壓縮的 CMYK TIFF?

[編輯 | 編輯原始碼]

Ghostscript 有五個用於顏色管理的 TIFF 裝置。以及五個 TIFF 壓縮裝置,它們只生成黑白影像。

 gs -sDEVICE=tif32nc -sOutputFile=tiger.tiff -dEPSCrop examples/tiger.eps

哪些 CJK 字型可以在 Ghostscript 上使用?

[編輯 | 編輯原始碼]

未受保護的 CJK 字型可以在 Ghostscript 上正常使用。無法安裝 CSL(Adobe 的 CID 支援庫),但大多數 PostScript 程式不需要它。CSL 模擬 OCF 結構,用於假設直譯器上存在 OCF 字型的作業,並直接操作它們。

Heisei 和 KozMin CIDFonts 是 Adobe Systems 開發的未受保護的專有字型。附帶字型的安裝程式在 Mac 上執行,並將字型安裝到使用 PAP 協議的網路印表機上。要在 Ghostscript 上安裝這些字型,您需要將 CIDFont 檔案複製到 Resource/CIDFont/ 目錄中。

CIDFont 資源隱藏在 Mac 檔案系統中不可見檔案的資源分叉中。 get-mac-cidfont 從輸入檔案(通常為/dev/cdrom)中提取所有 CIDFont 資源到目錄中。該程式也適用於 Windows NT。

如何在 PDF 中避免 JPEG 壓縮?

[編輯 | 編輯原始碼]

Ghostscript 具有過度激進的啟發式方法來識別用於 JPEG 壓縮的影像。使用setdistillerparams 運算子,可以手動選擇壓縮演算法。除了setdistillerparams 運算子外,Ghostscript 還接受大多數 distiller 引數(PDF 0.6M)作為命令列引數。

 ps2pdf -dAutoFilterColorImages#false -dColorImageFilter#/FlateEncode \
   -dAutoFilterGrayImages#false -dGrayImageFilter#/FlateEncode foo.ps foo.pdf

Ghostscript 開發人員已認識到這個問題。修復預計很快就會到來。

Ghostscript 在 findfont 中出現 /invalidfont 錯誤?

[編輯 | 編輯原始碼]

Ghostscript 很可能完全無法訪問任何字型。要檢查搜尋字型的目錄,請使用

 gs -h

 gswin32c -h

如何建立半透明物件?

[編輯 | 編輯原始碼]

Adobe 在 PDF 1.4 中引入了半透明物件。許多新的 RIP(包括 Ghostscript)直接接受 PDF 1.4。因此,PostScript 中的透明度功能不再需要。

  • Ghostscript 在 v. 8.00 及更高版本中支援 PDF 1.4
  • Adobe CPSI 在 v. 3015 及更高版本中支援 PDF 1.4

標準 PostScript 具有不透明的顏色模型。較新的物件完全遮蔽了底部的物件,但新物件的某些部分可以透過裁剪路徑從繪製中排除。在級別 3 PostScript 上,取樣影像可用於裁剪另一個取樣影像。在級別 2 上,可以透過在影像蒙版上繪製圖案顏色來實現類似的效果。

透過疊印專色和純過程色也可以實現非常有限的透明度效果。

Ghostscript 中的 PDF 1.4 直譯器是用擴充套件的 PostScript 語言實現的。擴充套件對常規 PostScript 檔案可見,並且可以用於實現相同的效果。該介面在 doc/language.htm 中有部分文件說明。有關詳細資訊,請閱讀原始碼。

PostScript 輸出干擾重定向的裝置輸出。

[編輯 | 編輯原始碼]

寫入 stdout 的 PostScript 檔案將干擾對 stdout 的裝置輸出。因此,從 v.7.04 開始,Ghostscript 可以將 PostScript %stdout 輸出分配給檔案,使實際的 stdout 對於裝置輸出(如使用-sOutputFile=--sOutputFile=%stdout)保持“乾淨”。

例如,當 Ghostscript 用作過濾器時,要丟棄 PS %stdout 輸出(例如,來自 '=' 運算子),正確的命令列是

 gs -q -sstdout=/dev/null -sOutputFile=- - | ...

藉助 bash 的一點幫助,可以將 命名管道 用作常規檔案的替代,避免所有 stdout-stderr 問題。

 gs -sDEVICE=pswrite -o >(wc) -c showpage

如何修復由 pswrite 裝置生成的的檔案

[編輯 | 編輯原始碼]

Adobe PostScript 直譯器和 Ghostscript v. 8.55 及更高版本在具有由舊版 Ghostscript(使用 Subversion 修訂版 1225 到 2334)生成的非標準頁面尺寸的檔案上出現/typecheck in --where-- 錯誤。受影響的程式碼執行null where,這在 PostScript 語言中是不允許的。

以下IdiomSet 資源可以安裝在 PostScript 直譯器上以解決此問題。要啟用IdiomSet,您需要將其複製到印表機或基於主機的直譯器上的/Resource/IdiomSet/ 目錄中。基於主機的直譯器上的 PostScript 根目錄可能與系統根目錄不同。檔名無關緊要,但建議使用FixOldPSwrite。對於一次性替換,您也可以將該檔案預先附加到您的作業檔案中。

 %!
 % This IdionSet provides backward compatibility with the old pdfwrite.
 % pswrite device in Ghostscript 7.04 and older generated incorrect
 % PostScript code. It assumed that the null value can be looked up in
 % a dictionary. Adobe interpreters never accepted null as dictionary
 % key and Ghostscript doesn't do this since v. 8.55. (rev. 6956)
 %
 currentuserparams /IdiomRecognition get
 <</IdiomRecognition false>> setuserparams
 currentglobal true setglobal
 /FixOldPSwrite
 << /fix_old_pswrite
     [
       { PageSize aload pop
         3 index eq exch 4 index eq and
           { pop pop pop
           }
           { PageSize dup
             1 5 -1 roll put
             0 4 -1 roll put dup where
               { exch get exec
               }
               { pop /setpagedevice where
                   { pop 1 dict dup /PageSize PageSize put setpagedevice
                   }
                   { /setpage where
                       { pop PageSize aload pop
                         pageparams 3 { exch pop } repeat setpage
                       }
                     if
                   }
                 ifelse
               }
             ifelse
           }
         ifelse
       } bind
       { PageSize aload pop
         3 index eq exch 4 index eq and
           { pop pop pop
           }
           { PageSize dup
             1 5 -1 roll put
             0 4 -1 roll put dup //null eq { false } { dup where } ifelse
               { exch get exec
               }
               { pop /setpagedevice where
                   { pop 1 dict dup /PageSize PageSize put setpagedevice
                   }
                   { /setpage where
                       { pop PageSize aload pop
                         pageparams 3 { exch pop } repeat setpage
                       }
                     if
                   }
                 ifelse
               }
             ifelse
           }
         ifelse
       } bind
     ]
 >> /IdiomSet defineresource pop
 setglobal <</IdiomRecognition 3 -1 roll>> setuserparams

Ghostscript 無法執行我的檔案

[編輯 | 編輯原始碼]

您嘗試學習 postscript,但無法做到

 $ gs
 GS>(test.ps)run

來自 gs 的堆疊轉儲在這裡 ....

Current allocation mode is local
Last OS error: Permission denied
...
GS>

從 9.50 版本開始,其他安全功能處於活動狀態。現在您需要

  $ gs -dNOSAFER
華夏公益教科書