Vous pouvez le faire avec PyPDF2. Le code ci-dessous n'est pas une solution parfaite à votre problème, mais il aidera, je l'espère, les personnes qui viennent ici depuis Google.
#!/usr/bin/env python
# requires PyPdf2 library, version 1.26 or above -
# its homepage is https://pythonhosted.org/PyPDF2/index.html
# running: ./this-script-name output.pdf file-with-pdf-list
import copy, sys
from PyPDF2 import PdfFileWriter, PdfFileReader, pdf
output = PdfFileWriter()
output_page_number = 0
alignment = 6 # align on 6 pages for printing 6 up
for filename in sys.argv[2:]:
page = pdf.PageObject.createBlankPage(None, 850, 1100)
input = PdfFileReader(open(filename, "rb"))
position = 0
for i in range(0, input.getNumPages()):
x = 0
# Two Up
# if position == 0:
# position = 1
# page.mergeScaledTranslatedPage(input.getPage(i), 0.5, 100, 650)
#else:
# page.mergeScaledTranslatedPage(input.getPage(i), 0.5, 100, 100)
# output.addPage(page)
# page = pdf.PageObject.createBlankPage(output)
# position = 0
# 6 Up
scale = 0.25
col1 = 100
col2 = 450
sep = 130
row3 = sep + 25
row2 = row3 + sep + 215
row1 = row2 + sep + 215
if position == 0:
position = 1
page.mergeScaledTranslatedPage(input.getPage(i), scale, col1, row1)
elif position == 1:
position = 2
page.mergeScaledTranslatedPage(input.getPage(i), scale, col2, row1)
elif position == 2:
position = 3
page.mergeScaledTranslatedPage(input.getPage(i), scale, col1, row2)
elif position == 3:
position = 4
page.mergeScaledTranslatedPage(input.getPage(i), scale, col2, row2)
elif position == 4:
position = 5
page.mergeScaledTranslatedPage(input.getPage(i), scale, col1, row3)
else:
page.mergeScaledTranslatedPage(input.getPage(i), scale, col2, row3)
output.addPage(page)
page = pdf.PageObject.createBlankPage(output)
position = 0
if position != 0:
output.addPage(page)
output.write(open(sys.argv[1], "wb"))