Need to Programmatically Convert PDF Paper Size (e.g. US-Letter to A4) in Python (or command line) [closed]

帅比萌擦擦* 提交于 2021-02-10 12:16:50

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/36950487/need-to-programmatically-convert-pdf-paper-size-e-g-us-letter-to-a4-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!