Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What dimensions do the coordinates in PDF cropbox refer to?

If one has, for example, a pdf with the wrong page size specified one can crop away the unwanted portions of the document with ghostscript and the command parameter /CropBox. My question is, what do the numbers in the command refer to? I know they are point units (72nds of an inch) but what are their origins and axes?

By dint of trail and error from this example I've come up with following to keep an area approximately 6"x4" from the top left corner of a 11"x8.5" page (example source pdf). I'd like to do the math though and get my numbers precise instead of approximate (my final page needs to be landscape A6, 5.83"x4.13").

gswin64c ^
-o fixed-A6.pdf ^
-sDEVICE=pdfwrite ^
-c "[/CropBox [0 315 420 610] /PAGES pdfmark" ^
-f landscape-letter-size.pdf

Also, are the brackets [ ] supposed to be unbalanced? The opening [/Crop... doesn't have a corresponding close.

like image 523
matt wilkie Avatar asked Nov 16 '11 20:11

matt wilkie


1 Answers

They have the same origin as the other boxes defined in the Page object (eg default to units in Points with the origin to the lower left corner. You can see the PDF 1.7 documentation for further reference. There are some commands that can reside on higher level objects (Pages) that change the coordinate system by the way but those are rare (and when you create your PDF yourself with ghostscript you would know)..

Each number is referenced from the bottom left corner margin. So from the example 0 315 means 0pt from the left and 315pt above the bottom, and 420 610 is the opposite corner of the rectangle, from the same origin. [0 315 420 610] = rectangle (left bottom right top)

     ****************************************************
 610 ----------------------X 420,610                    *
     |                     |                            *
     |                     |                            *
     |                     |                            *
     |                     |                            *
     |                     |                            *
     |                     |                            *
     |                     |                            *
     |0,315                |                            *
 315 X----------------------                            *
     *                                                  *
     *                                                  *
     *                                                  *
     *                                                  *
     *                                                  *
     *                                                  *
     *                                                  *
     *                                                  *
   0 ****************************************************
     0                    420
like image 91
Ritsaert Hornstra Avatar answered Nov 15 '22 15:11

Ritsaert Hornstra