9

If one has, for example, a pdf with the wrong page size specified one can crop away the unwanted portions of the document with 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.

Community
  • 1
  • 1
matt wilkie
  • 17,268
  • 24
  • 80
  • 115
  • 1
    In PDFs, the 0,0 origin is actually the bottom left corner of the page, and positive coordinates go up and to the right. – Marc B Nov 16 '11 at 20:45
  • 1
    `pdfmark` *is* the right-bracket. Recall that `[`, `<<`, and `mark` are all equivalent. – luser droog Nov 18 '11 at 06:00

1 Answers1

18

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
matt wilkie
  • 17,268
  • 24
  • 80
  • 115
Ritsaert Hornstra
  • 5,013
  • 1
  • 33
  • 51
  • Ok, so then from my example "0,315" is the lower left origin of the cropbox, expressed as distance from the lower left corner of the page, correct? Does that make "410,615" x,y distance from the lower left of the page or lower left of the cropbox (the preceding couplet)? – matt wilkie Nov 16 '11 at 21:13
  • @Matt: 0,315 means 0pt from the left margin (eg onto the left margin) and 315pt above the bottom margin, so if the page is around A4 in size this is about halfway of the page. [0 315 420 610 ] = rectangle ( left bottom right top ) all as pt from left (horizontal) and bottom (vertical). – Ritsaert Hornstra Nov 17 '11 at 15:12
  • Thanks for clarification. *"You can see the PDF 1.7 documentation for further reference."* - I would if I could find it. The only source I've located wants over $600 for it (https://www.standardsstore.ca/eSpecs/DocumentDetails.do?GID=GWSJHCAAAAAAAAAA&currency=CAD). – matt wilkie Nov 17 '11 at 18:33
  • Strange, I could have sworn I was on that same page a few hours ago, and the two pdf docs listed only had half a dozen pages, just covering extensions to the reference. {shrug} oh well, thanks! – matt wilkie Nov 17 '11 at 23:28