title: Cropping a PDF / Adding crop box using Ghostscript
body: <p>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.</p>
  
  <p>How can I do this using Ghostscript (v8.71)?  I found this:</p>
  
  <p><code>gs -sDEVICE=pdfwrite -sOutputFile=marked.pdf [/CropBox [54 54 1314 810] /PAGES pdfmark original.pdf</code></p>
  
  <p>I've tried this (and all variants I can think of) but I always get an error such as this:</p>
  
  <p><code>Error: /undefinedfilename in ([/CropBox)</code></p>
  
  <p>I've tried moving around the parameters of the command but nothing seems to work.  Does anyone know how this can be accomplished?</p>
  
  <p><b>Update: Still no crop box after correcting syntax, see results -</b></p>
  
  <p>Results for: <code>pdfinfo -box -f 1 -l 3 original.pdf</code></p>
  
  <pre><code>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`
  </code></pre>
  
  <p><br />
  Results for: <code>pdfinfo -box -f 1 -l 3 marked.pdf</code></p>
  
  <pre><code>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
  </code></pre>
  
  <p><b>Update: Example PDFs posted -</b></p>
  
  <p>&bull; <a href="https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=true&amp;srcid=0ByiDK4uFbwYHYmU2NWMwZTQtYWVjZi00ZDNjLTgzOWMtZmNhNjE3YzE1MjYy&amp;hl=en" rel="noreferrer">able_to_crop.pdf</a><br />
  &bull; <a href="https://docs.google.com/viewer?a=v&amp;pid=explorer&amp;chrome=true&amp;srcid=0ByiDK4uFbwYHMmY1YTUxNjItZmYwYy00MzkxLTkyNjUtMDNjNzJmOThiYjNk&amp;hl=en" rel="noreferrer">cannot_crop.pdf</a></p>