AME*_*MER 37 pdf crop ghostscript
我不是程序员,但想学习如何使用Ghostscript裁剪PDF.
我在我的机器上安装了Ghostscript 9.01.
请指导我一步一步的过程(从调用Ghostscript开始)来裁剪具有特定坐标的PDF.
我甚至是Ghostscript的新手.
Kur*_*fle 65
首先,请注意PDF的测量单位与PostScript相同:它称为点 [pt].
72 points == 1 inch == 25.4 millimeters
Run Code Online (Sandbox Code Playgroud)
假设您的页面大小为A4.然后媒体维度是:
595 points width == 210 millimeters
842 points height == 297 millimeters
Run Code Online (Sandbox Code Playgroud)
假设您要裁剪:
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
Run Code Online (Sandbox Code Playgroud)
然后你的Ghostscript命令行就是这个(在Windows上):
gswin32c.exe ^
-o cropped.pdf ^
-sDEVICE=pdfwrite ^
-c "[/CropBox [24 72 559 794]" ^
-c " /PAGES pdfmark" ^
-f uncropped-input.pdf
Run Code Online (Sandbox Code Playgroud)
或者在Linux上:
gs \
-o cropped.pdf \
-sDEVICE=pdfwrite \
-c "[/CropBox [24 72 559 794]" \
-c " /PAGES pdfmark" \
-f uncropped-input.pdf
Run Code Online (Sandbox Code Playgroud)
但是,对于所有类型的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
Run Code Online (Sandbox Code Playgroud)
要么
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
Run Code Online (Sandbox Code Playgroud)
[^]:更具体一点:它不适用于/CropBox
已经定义为特定值的PDF .一个肮脏的黑客是在运行上面的GS命令之前用文本编辑器更改/CropBox
所需页面的所有页面/cROPBoX
(或类似的大小写更改).大小写更改有效地"撤消"裁剪框设置(不更改任何PDF对象偏移使现有xref
表无效),因此PDF渲染器不再考虑它.