-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_pages.py
More file actions
23 lines (18 loc) · 781 Bytes
/
extract_pages.py
File metadata and controls
23 lines (18 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import fitz
import argparse
parser = argparse.ArgumentParser(description="Enumerate the pages in a PDF file")
def main():
parser.add_argument("-i", "--input", help="the PDF file to enumerate")
parser.add_argument("-o", "--output", help="the directory to write the output files to")
parser.add_argument("-d", "--dpi", help="the DPI to use when rendering the pages", default=96, type=int)
args = parser.parse_args()
if not os.path.exists(args.output):
os.makedirs(args.output)
pdf_file = fitz.open(args.input)
for page in range(len(pdf_file)):
print("Extracting page %d" % page)
pix = pdf_file[page].get_pixmap(dpi=args.dpi)
pix.save(args.output + "/page-%d.png" % page)
if __name__ == "__main__":
main()