簡體   English   中英

使用 Ghostscript 9.01 裁剪 PDF

[英]Cropping a PDF using Ghostscript 9.01

我不是程序員,但想學習如何使用 Ghostscript 裁剪 PDF。

我已經在我的機器上安裝了 Ghostscript 9.01。

請指導我一步一步的過程(從調用 Ghostscript 開始)裁剪具有特定坐標的 PDF。

我什至是 Ghostscript 的新手。

首先,請注意 PDF 的測量單位與 PostScript 相同:稱為[pt]。

72 points == 1 inch == 25.4 millimeters

假設您的頁面大小為 A4。 那么媒體維度是:

595 points width  == 210 millimeters
842 points height == 297 millimeters

假設您要裁剪:

   left edge: 24 points == 1/3 inch ~=  8.5 millimeters
  right edge: 36 points == 1/2 inch ~= 12.7 millimeters
    top edge: 48 points == 2/3 inch ~= 17.0 millimeters
 bottom edge: 72 points ==   1 inch ~= 25.4 millimeters

然后你的 Ghostscript 命令行是這樣的(在 Windows 上):

gswin32c.exe                     ^
  -o cropped.pdf                 ^
  -sDEVICE=pdfwrite              ^
  -c "[/CropBox [24 72 559 794]" ^
  -c " /PAGES pdfmark"           ^
  -f uncropped-input.pdf

或在 Linux 上:

gs                               \
  -o cropped.pdf                 \
  -sDEVICE=pdfwrite              \
  -c "[/CropBox [24 72 559 794]" \
  -c " /PAGES pdfmark"           \
  -f uncropped-input.pdf

但是,這可能不適用於所有類型的 PDF [1] 在這些情況下,您應該選擇嘗試以下命令:

gswin32c.exe                 ^
  -o cropped.pdf             ^
  -sDEVICE=pdfwrite          ^
  -dDEVICEWIDTHPOINTS=595    ^
  -dDEVICEHEIGHTPOINTS=842   ^
  -dFIXEDMEDIA               ^
  -c "24 72 translate"       ^
  -c " 0 0 535 722 rectclip" ^
  -f uncropped-input.pdf

或者

gs                           \
  -o cropped.pdf             \
  -sDEVICE=pdfwrite          \
  -dDEVICEWIDTHPOINTS=595    \
  -dDEVICEHEIGHTPOINTS=842   \
  -dFIXEDMEDIA               \
  -c "24 72 translate"       \
  -c " 0 0 535 722 rectclip" \
  -f uncropped-input.pdf

[^]更具體地說:它不適用於帶有已經定義為特定值的/CropBox的 PDF。 一個骯臟的技巧是在運行上述 GS 命令之前使用文本編輯器更改所有頁面的字符串/CropBox以使用/cROPBoX (或類似的大小寫更改)。 大小寫更改有效地“解除”裁剪框設置(不更改任何 PDF object 偏移量,使現有xref表無效),因此 PDF 渲染器不再考慮它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM