Initial attempt at imposition
This commit is contained in:
commit
a7fc1e047c
2 changed files with 46 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
venv
|
||||||
|
__pycache__
|
||||||
44
pympose.py
Normal file
44
pympose.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import pypdf
|
||||||
|
|
||||||
|
|
||||||
|
def main(source, out, section_length):
|
||||||
|
assert section_length % 4 == 0
|
||||||
|
in_reader = pypdf.PdfReader(source)
|
||||||
|
out_writer = pypdf.PdfWriter()
|
||||||
|
|
||||||
|
to_add = section_length - len(in_reader.pages) % section_length
|
||||||
|
add_before = to_add // 2
|
||||||
|
add_after = to_add - add_before
|
||||||
|
|
||||||
|
pages = [pypdf.PageObject.create_blank_page(in_reader) for _ in range(add_before)]
|
||||||
|
pages += in_reader.pages
|
||||||
|
pages += [pypdf.PageObject.create_blank_page(in_reader) for _ in range(add_after)]
|
||||||
|
|
||||||
|
for sig_start in range(0, len(in_reader.pages), section_length):
|
||||||
|
for side in range(section_length // 4):
|
||||||
|
top = [
|
||||||
|
sig_start + section_length - side - 1,
|
||||||
|
sig_start + side,
|
||||||
|
]
|
||||||
|
bottom = [
|
||||||
|
sig_start + section_length // 2 + side,
|
||||||
|
sig_start + section_length // 2 + side - 1,
|
||||||
|
]
|
||||||
|
|
||||||
|
if side % 2 != 0:
|
||||||
|
top = list(reversed(top))
|
||||||
|
bottom = list(reversed(bottom))
|
||||||
|
|
||||||
|
|
||||||
|
print(top)
|
||||||
|
print(bottom)
|
||||||
|
|
||||||
|
continue
|
||||||
|
for si, pi in enumerate(range(sig_start, sig_start + section_length)):
|
||||||
|
page_box = pages[pi]
|
||||||
|
trans = pypdf.Transformation()
|
||||||
|
|
||||||
|
if si >= section_length // 4 and si < 3 * section_length // 4:
|
||||||
|
trans = trans.rotate(180)
|
||||||
|
|
||||||
|
trans = trans.scale(0.5, 0.5)
|
||||||
Loading…
Add table
Reference in a new issue