You can do this with PyPDF2. The code below is not a perfect solution to your problem, but it will hopefully help others who come here from 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"))
I don't think that this is possible, do you only have the pdf? – Michael K – 2011-02-15T15:31:44.657
This is possible on Linux using pstops from the psutils package and/or pdftk.
Which operating system are you running? – rems – 2011-02-15T15:31:50.257
@Ivo Flipse: har, i thought the exactly the same :) so, your comment gets a +1 as well. – akira – 2011-02-15T17:54:35.887
@Ivo Flipse, @rems: You can upvote more ASCII art here: http://superuser.com/questions/54054/convert-pdf-2-sides-per-page-to-1-side-per-page/189109#189109 and http://superuser.com/questions/235074/freeware-to-split-a-pdfs-pages-down-the-middle/235401#235401 ... @mokasin: these links may give you an idea how to solve the task you asked for.
– Kurt Pfeifle – 2011-03-01T22:05:11.543