This repository was archived by the owner on Feb 5, 2026. It is now read-only.
forked from mfenniak/pyPdf
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME
More file actions
61 lines (49 loc) · 1.58 KB
/
README
File metadata and controls
61 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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()