使用Ghostscript裁剪PDF/添加裁剪框 [英] Cropping a PDF / Adding crop box using Ghostscript

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

问题描述

我需要裁剪几百个PDF-我愿意裁剪实际文档,或者只是在每个文档中添加一个裁剪框,以便在打开PDF时显示正确的可视区域.

I have a few hundred PDFs that I need to crop - I'm willing to either crop the actual documents or simply add a crop box to each so the correct viewable area shows when the PDF is opened.

如何使用Ghostscript(v8.71)执行此操作?我发现了:

How can I do this using Ghostscript (v8.71)? I found this:

gs -sDEVICE=pdfwrite -sOutputFile=marked.pdf [/CropBox [54 54 1314 810] /PAGES pdfmark original.pdf

我已经尝试过了(我可以想到的所有变体),但是我总是会遇到这样的错误:

I've tried this (and all variants I can think of) but I always get an error such as this:

Error: /undefinedfilename in ([/CropBox)

我尝试在命令的参数周围移动,但是似乎没有任何效果.有谁知道如何做到这一点?

I've tried moving around the parameters of the command but nothing seems to work. Does anyone know how this can be accomplished?

更新:更正语法后仍然没有裁剪框,​​请参见结果-

结果:pdfinfo -box -f 1 -l 3 original.pdf

Producer:       PDFlib 7.0.2 (PHP5/Linux)
CreationDate:   Wed Oct 21 11:41:04 2009
ModDate:        Wed Oct 21 13:38:22 2009
Tagged:         no
Pages:          1
Encrypted:      no
Page    1 size: 1423 x 918 pts
Page    1 MediaBox:     0.00     0.00  1423.00   918.00
Page    1 CropBox:      0.00     0.00  1423.00   918.00
Page    1 BleedBox:    54.00    54.00  1369.00   864.00
Page    1 TrimBox:      0.00     0.00  1423.00   918.00
Page    1 ArtBox:       0.00     0.00  1423.00   918.00
File size:      914373 bytes
Optimized:      no
PDF version:    1.4`


结果:pdfinfo -box -f 1 -l 3 marked.pdf


Results for: pdfinfo -box -f 1 -l 3 marked.pdf

Producer:       GPL Ghostscript 8.71
CreationDate:   Wed Apr 27 15:43:38 2011
ModDate:        Wed Apr 27 15:43:38 2011
Tagged:         no
Pages:          1
Encrypted:      no
Page    1 size: 1423 x 918 pts
Page    1 MediaBox:     0.00     0.00  1423.00   918.00
Page    1 CropBox:      0.00     0.00  1423.00   918.00
Page    1 BleedBox:     0.00     0.00  1423.00   918.00
Page    1 TrimBox:      0.00     0.00  1423.00   918.00
Page    1 ArtBox:       0.00     0.00  1423.00   918.00
File size:      392382 bytes
Optimized:      no
PDF version:    1.4

更新:示例PDF发布-

• able_to_crop.pdf
• cannot_crop.pdf

推荐答案

您在正确的轨道上,尝试使用pdfmark/Ghostscript添加CropBox.但是您的语法不是100%正确.

You are on the right track, trying to use pdfmark/Ghostscript for adding a CropBox. But your syntax isn't 100% correct.

尝试以下方法:

 gs \
  -sDEVICE=pdfwrite \
  -o marked.pdf \
  -c "[/CropBox [54 54 1314 810] /PAGES pdfmark" \
  -f original.pdf

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

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