2

I need to convert PDF documents from one arbitrary page size to another.

For example, I might have a bunch of PDF documents formatted for us-letter paper (8.5" x 11") that I need to convert to the A4 paper size (21 cm x 29.7 cm), or I might need to convert A3 to ledger-size, etc.

This seems like it should be a simple task but my Google-fu is failing me.

It would be neat if I could actually re-flow the text of the documents to take better advantage of the new size and aspect ratio, but I'm not expecting that. It is sufficient to scale the up or down to fit within the new page size.

The rest of my program happens to be written in Python, and a Python-based solution would be nice, but a command line tool would be fine as long as I can run it on Linux/Unix/OSX.

Any suggestions on how best to go about this?

Lela Jennings
  • 78
  • 1
  • 8
  • I don't mean to be difficult, but I believe that "good answers would be too long for this format" is demonstrably false. Klaus's answer below (which I've just accepted but I don't have the karma to upvote) is a specific and concise answer to my question. "How do I convert a PDF from us-letter to A4 with python and/or the linux command line?" seems like a pretty specific question to me. – Lela Jennings May 05 '16 at 05:13
  • I should add, ssinfod's answer is also a direct, specific and concise answer to this question. (But one that suffers from other issues, as discussed in the comments to that answer.) – Lela Jennings May 05 '16 at 05:14

2 Answers2

4

You could use

  • Ghostscript using the -sPAPERSIZE=a4 switch, see chapter 3.3 the docs or a full solution here on SO, or
  • pdfjam(a shell script that is part of texlive), with the --paper a4paper option, as described of unix.SE
Community
  • 1
  • 1
Klaus-Dieter Warzecha
  • 2,027
  • 2
  • 23
  • 31
  • 1
    Ghostscript will fully parse the input PDF file and will recompress bitmap images, producing a lower quality output PDF. You want to use a tool that embeds the original PDF's pages as-is into the output PDF. This will be much faster too. I'm not sure, but I suspect this is how `pdfjam` works. – Brecht Machiels Apr 30 '16 at 11:30
  • @BrechtMachiels True for the defaults of `gs`, but this behaviour can be controlled by the different `-dDownsampleWhatnotImages=false` options, isn't it? – Klaus-Dieter Warzecha Apr 30 '16 at 11:39
  • 1
    Yes, somewhat, but I have never been able to get satisfactory results from it. It is best to completely avoid recompression of the images. – Brecht Machiels Apr 30 '16 at 12:23
  • 1
    Thanks @klaus-warzecha. The pdfjam solution as described in the [linked unix.stackexchange thread](http://unix.stackexchange.com/questions/185145/convert-pdf-to-a-different-page-size-us-letter-a4) seems pretty promising. I'll give that a try and report back. – Lela Jennings Apr 30 '16 at 16:10
  • 1
    Although I accepted this answer I never actually "reported back" via a comment. Thanks again @KlausWarzecha, the pdfjam suggestion meets my needs. – Lela Jennings May 14 '16 at 00:08
  • @LelaJennings No problem, but thanks for the nice thought! Accepting an answer is the perfect way to "report back". – Klaus-Dieter Warzecha May 14 '16 at 04:58
-1

In ubuntu, I would use "convert" from the command line.

This line is working for me to convert from Letter to A4 :

convert -page A4 a.pdf a2.pdf

See the -page parameter on the imagemagick website for more details:

http://www.imagemagick.org/script/command-line-options.php#page

ssinfod
  • 935
  • 2
  • 13
  • 28