使用 Ghostscript 9.01 裁剪 PDF [英] Cropping a PDF using Ghostscript 9.01

查看:53
本文介绍了使用 Ghostscript 9.01 裁剪 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是程序员,但想学习如何使用 Ghostscript 裁剪 PDF.

I am not a programmer, but would like to learn how to crop a PDF using Ghostscript.

我已经在我的机器上安装了 Ghostscript 9.01.

I have installed Ghostscript 9.01 in my machine.

请指导我逐步(从调用 Ghostscript 开始)使用特定坐标裁剪 PDF.

Please guide me step by step process (starting from invoking Ghostscript) to crop a PDF with the specific coordinates.

我什至是 Ghostscript 的新手.

I am even new to Ghostscript.

推荐答案

首先,请注意 PDF 的度量单位与 PostScript 相同:称为 point [pt].

First, take note that the measurement unit for PDF is the same as for PostScript: it's called a point [pt].

72 points == 1 inch == 25.4 millimeters

假设您的页面大小为 A4.那么媒体维度是:

Assuming you have a page size of A4. Then the media dimensions are:

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 上):

Then your Ghostscript commandline is this (on Windows):

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

或者在 Linux 上:

Or on Linux:

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

但是,这可能不适用于所有类型的 PDF[1].在这些情况下,您也应该尝试以下命令:

However, this may not work reliably for all types of PDFs [1]. In those cases you should alternatively try these commands:

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已经定义为特定值.一个肮脏的黑客是在运行之前使用文本编辑器更改所有需要 /cROPBoX(或类似的大小写更改)的页面的字符串 /CropBox上面的 GS 命令.大小写更改有效地解除"了cropbox 设置(不更改任何使现有xref 表无效的PDF 对象偏移量),因此PDF 渲染器不再考虑它.


[^] : To be more specific: it will not work for PDFs which come along with their own /CropBox already defined to specific values. A dirty hack around that is to change the string /CropBox for all pages where it is desired to /cROPBoX (or similar case-changing) with a text editor prior to running the above GS command. The case-change effectively "disarms" the cropbox setting (without changing any PDF object offsets invalidating the existing xref table) so it is no longer considered by PDF renderers.

这篇关于使用 Ghostscript 9.01 裁剪 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆