Using ImageMagick or Ghostscript (or something) to scale PDF to fit page?

本秂侑毒 提交于 2019-12-02 17:18:46

The problem with using ImageMagick is that you are converting to a raster image format, increasing file size and decreasing quality for any vector elements on your pages.

Multivalent will retain the vector information of the PDF. Try:

java -cp Multivalent.jar tool.pdf.Impose -dim 1x1 -paper "8.5x11in" myFile.pdf

to create an output file myFile-up.pdf

I would not use convert. It uses Ghostscript in the background, but is much slower. I'd use Ghostscript directly, since it gives me much more direct control (and also some control over settings which are much more difficult to achieve with convert). And for convert to work for PDF-to-PDF conversion you'll have Ghostscript installed anyway:

  gs \
    -o /path/to/resized.pdf \
    -sDEVICE=pdfwrite \
    -dPDFFitPage \
    -r300x300 \
    -g2550x3300 \
    /path/to/original.pdf

ImageMagick's mogrify/convert commands will indeed do the job. Stephen Page had just about the right idea, but you do need to set the dpi of the file as well, or you won't get the job done.

Assuming you have a file that's 300 dpi and already the same aspect ratio as 8.5 x 11 the command would be:

// 300dpi x 8.5 -2550, 300dpi x 11 -3300
convert original.pdf -density "300" -resize "2550x3300" resized.pdf

If the aspect ratio is different, then you need to do some slightly trickier cropping.

Jon Ahlquist

The Ghostscript approach worked well for me. (I moved my file from my Windows PC to a Linux computer and ran it there.) I made one small change to the Ghostscript command because the Ghostscript resize command above completely fills an 8.5 by 11 inch page. My printer cannot print to the edge, though, so several milllimeters along each page edge were lost. To overcome that problem, I scaled my PDF document to 0.92 of a full 8.5 by 11 inches. That way I saw everything centered on the page and had a slight margin. Because 0.92 * (2550x3300) = (2346x3036), I ran the following Ghostscript command:

  gs -sDEVICE=pdfwrite \
     -dPDFFitPage \
     -r300x300 \
     -g2346x3036 \
     /home/user/path/original.pdf \
     -o /home/user/path/resized.pdf
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!