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

后端 未结 1 1272
慢半拍i
慢半拍i 2021-01-14 14:01

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=le         


        
相关标签:
1条回答
  • 2021-01-14 14:36

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

    Your problem is that the original PDF file contains a CropBox, which is retained by the Ghostscript pdfwrite device. The output from pdfinfo is telling you the size of the PDF file, taking the CropBox into account. The MediaBox is in fact 612x792, ie exactly 8.5x11, which is what you wanted.

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

    If you don't want the CropBox to be preserved, you will have to construct a new CropBox Page or PAGES pdfmark and send it as PostScript. This isn't entirely non-trivial; in your case each page has a CropBox (its not a single default for the entire document), so you need to override the CropBox on each page. To do this you need to define a /EndPage procedure which sets the desired CropBox using a pdfmark, and send that before you process the PDF file.

    This :

    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.

    0 讨论(0)
提交回复
热议问题