0

How can I convert an A3 pdf to A4 pdf in python. I need a way that can be applied in all platforms-Windows, Mac and Linux. So something like this maybe:

import os
os.system(' command to convert A3 to A4 pdf ')

So far I found many ways to do it in Linux from here: Need to Programmatically Convert PDF Paper Size (e.g. US-Letter to A4) in Python (or command line)

I think it can be done via ImageMagick also(http://www.imagemagick.org/script/command-line-options.php#page) but I am not sure how to implement it correctly. I tried:

pdf_folder = os.listdir(infolder)
pdf_files = [_ for _ in pdf_folder if _[-4:] == ".pdf"]
print("Available PDFs:\n")
for pdffile in pdf_files:
    print(pdffile)
    convert  -page a4 pdffile pdffile

But this gives a invalid syntax error

Amrita Deb
  • 117
  • 1
  • 3
  • 12
  • Imagemagick will rasterize your PDF if it was a vector file. It will not produce a new vector file. If that is OK, then `convert A3.pdf -resize 595x842 A4.pdf` If on the IM 7.0.10.35 then `magick A3.pdf -resize "%[papersize:A4]" A4.pdf` – fmw42 Nov 03 '20 at 17:32
  • the convert command is giving me an error `Invalid Parameter - -resize` and the magick command is giving me the error `magick: unknown image property "%[papersize:A4]" @ warning/property.c/InterpretImageProperties/4081. magick: invalid argument for option '-resize' '' at CLI arg 2 @ error/operation.c/CLISimpleOperatorImage/3221.` – Amrita Deb Nov 04 '20 at 07:08
  • That argument is not available in IM 6 and only available in the most current version of IM 7 --- 7.0.10.35 – fmw42 Nov 04 '20 at 19:26
  • I have ImageMagick 7.0.10-33 installed. – Amrita Deb Nov 05 '20 at 07:54
  • You will need to upgrade to use [papersize:A4] It needs 7.0.10.35 – fmw42 Nov 05 '20 at 17:02

0 Answers0