How it works...

First, we import the argparse, datetime, and sys libraries along with the newly installed PyPDF2 module.

from __future__ import print_functionfrom argparse import ArgumentParser, FileTypeimport datetimefrom PyPDF2 import PdfFileReaderimport sys

This recipe's command-line handler accepts one positional argument, PDF_FILE, which represents the file path to the PDF to process. For this script, we need to pass an open file object to the PdfFileReader class, so we use the argparse.FileType handler to open the file for us.

parser = ArgumentParser(    description=__description__,    epilog="Developed by {} on {}".format(", ".join(__authors__), __date__))parser.add_argument('PDF_FILE', help='Path to PDF file',                    type=FileType('rb'))args = ...

Get Python Digital Forensics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.