Cropping a PDF / Adding crop box using Ghostscript

大憨熊 提交于 2019-12-18 03:37:08

问题


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.

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?

Update: Still no crop box after correcting syntax, see results -

Results for: 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`


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

Update: Example PDFs posted -

• able_to_crop.pdf
• cannot_crop.pdf


回答1:


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

Try this instead:

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


来源:https://stackoverflow.com/questions/5797841/cropping-a-pdf-adding-crop-box-using-ghostscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!