Pure-Python PDF Library
Python
Switch branches/tags
Nothing to show
Pull request Compare This branch is 3 commits ahead of mfenniak:trunk.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
pyPdf
.gitignore
CHANGELOG
LICENSE
MANIFEST.in
README
setup.py

README

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from pyPdf_e import PdfFileWriter, PdfFileReader


output = PdfFileWriter()
input1 = PdfFileReader(file("pdf/demo.pdf", "rb"))


start = time.time()
for a in range(0, input1.getNumPages() - 2 , 2) :
    first = input1.getPage(a)
    second = input1.getPage(a + 1)
    width = first.mediaBox.getUpperRight_x()
    height = first.mediaBox.getUpperRight_y()
    first.mediaBox.upperRight = ( width * 2, height)
    first.mergeTranslatedPage(second,width,0)
    output.addPage(first)
    print a

end = time.time()
print "===>", end - start

# finally, write "output" to document-output.pdf
outputStream = file("document-output.pdf", "wb")
output.write(outputStream)
outputStream.close()


output = PdfFileWriter()
input1 = PdfFileReader(file("pdf/demo.pdf", "rb"))

start = time.time()
for a in range(0, input1.getNumPages() - 2 , 2) :
    new  = output.addBlankPage(100,100)    
    first = input1.getPage(a)
    second = input1.getPage(a + 1)
    width = first.mediaBox.getUpperRight_x()
    height = first.mediaBox.getUpperRight_y()
    new.mediaBox.upperRight = ( width * 2, height)
    data_x = []
    data_x.append("q\n")
    data_x.append("0.9 0 0 0.9 0 0 cm")
    data_x.append(first)
    data_x.append("Q\n")
    data_x.append("q\n")
    data_x.append("1 0 0 1 595 0 cm ")
    data_x.append(second)
    data_x.append("Q\n")
    new.mergePage3(data_x)
    print a

end = time.time()
print "===>", end - start

# finally, write "output" to document-output.pdf
outputStream = file("document-output2.pdf", "wb")
output.write(outputStream)
outputStream.close()