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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.