SHARE
TWEET

Untitled

a guest Feb 26th, 2011 352 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from pyPdf import PdfFileWriter, PdfFileReader
  5. import sys
  6.  
  7. #~ if sys.argv.length < 1:
  8.         #~ exit(0)
  9. filename = sys.argv[1]
  10.  
  11. output = PdfFileWriter()
  12. input1 = PdfFileReader(file(filename,"rb"))
  13. input2 = PdfFileReader(file(filename,"rb"))
  14.  
  15.  
  16.  
  17. for i in range(input1.getNumPages()):
  18.         page_right = input1.getPage(i)
  19.        
  20.         page_right.mediaBox.upperRight = (
  21.                 page_right.mediaBox.getUpperRight_x(),
  22.                 page_right.mediaBox.getUpperRight_y() / 2 + 30,
  23.         )
  24.         page_right.mediaBox.lowerLeft = (0,30)
  25.        
  26.         output.addPage(page_right)
  27.  
  28.         page_left = input2.getPage(i)
  29.  
  30.         page_left.mediaBox.lowerLeft = (        
  31.                 0,
  32.                 page_left.mediaBox.getUpperRight_y() / 2 - 30
  33.         )
  34.         page_left.mediaBox.upperRight = (      
  35.                 page_left.mediaBox.getUpperRight_x(),
  36.                 page_left.mediaBox.getUpperRight_y() - 30
  37.         )
  38.  
  39.  
  40.         output.addPage(page_left)
  41.        
  42.  
  43. outputStream = file("output.pdf","wb")
  44. output.write(outputStream)
  45. outputStream.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top