How do I resize a PDF file to 8.5 x 11 inches using Ghostscript?

Consider this PDF . I am trying to convert it to standard letter size (8.5 x 11) using the following command.

gs -dFIXEDMEDIA -dBATCH -dNOPAUSE -sPAPERSIZE=letter \
   -dPDFFitPage -q -sDEVICE=pdfwrite -sOutputFile=out.pdf \
    dean08mapreduce.pdf

      

Here pdfinfo

at the exit.

Producer:       GPL Ghostscript 9.10
CreationDate:   Mon Nov 17 18:25:01 2014
ModDate:        Mon Nov 17 18:25:01 2014
Tagged:         no
Form:           none
Pages:          7
Encrypted:      no
Page size:      596.225 x 792 pts
Page rot:       0
File size:      126908 bytes
Optimized:      no
PDF version:    1.4

      

Here pdfinfo

on the original:

Producer:       Creo Normalizer JTP
CreationDate:   Fri Dec 21 09:09:07 2007
ModDate:        Fri Dec 21 14:46:23 2007
Tagged:         no
Form:           AcroForm
Pages:          7
Encrypted:      no
Page size:      603 x 801 pts
Page rot:       0
File size:      235239 bytes
Optimized:      yes
PDF version:    1.3

      

Note that the exit has the correct height, but not the correct width. It's effective 8.3 x 11

, not 8.5 x 11

.

I've tried the solutions here and here , but didn't get what I need.

How do I get the PDF to be accurate 8.5 x 11

?

I don't mind if it involves adding a little space on both sides.

+3


source to share


1 answer


Double conversion is not a good plan, you can introduce problems at every step, especially since PostScript does not support the PDF graphics model (in particular, it does not support transparency)

Your problem is that the original PDF contains a CropBox which is saved by the Ghostscript pdfwrite application. The output from pdfinfo tells you the size of the PDF file, taking the CropBox into account. The MediaBox is actually 612x792, which is exactly 8.5x11 what you wanted.

The reason the height is set differently is because the new MediaBox is inside the original CropBox, so it is the intersection of the two boxes.

If you don't want the CropBox to be saved, you will need to create a new CropBox or PAGES pdf file and send it as PostScript. This is not entirely non-trivial; in your case there is a CropBox on every page (this is not the only default for the whole document), so you need to override the CropBox on every page. To do this, you need to define a procedure / EndPage that sets up the desired CropBox with pdfmark and submits this one before the PDF is processed.



It:

gs -sDEVICE=pdfwrite \
   -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -dFIXEDMEDIA \
   -sOutputFile=out.pdf \
   -c "<</EndPage {0 eq {[/CropBox [0 0 612 792] /PAGE pdfmark true}{false}ifelse}>> setpagedevice" \
   -f dean08mapreduce.pdf

      

Worked for me.

+4


source







All Articles