Skip to content

Instantly share code, notes, and snippets.

Last active June 2, 2020 07:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save josephernest/683887b2692ede80d30afa7d6d25bd8c to your computer and use it in GitHub Desktop.
Cut PDF pages in two halfs + rotated (ready for ereaders!)
import os, glob, pdfrw # todo: pip install pdfrw
for f in glob.glob('*.pdf'):
if '_cut.pdf' in f:
writer = pdfrw.PdfWriter()
for page in pdfrw.PdfReader(f).pages:
for y in [0, 0.5]:
newpage = pdfrw.PageMerge()
newpage.add(page, viewrect=(0, y, 1, 0.5))
p = newpage.render()
p.Rotate = 270
writer.write(f[:-4] + '_cut.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment