from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfdevice import PDFDevice

import pikepdf

pdfFile = '/home/yikang/Dropbox/disclosures-data/Yikang-Yang/United_States/data_2014/2014_Beatty,Hon.Joyce_OH03_FD Original.pdf'

# open a pdf file
# fp = open(pdfFile, 'rb')
fp = pikepdf.open(pdfFile)


# Create a PDF parser object associated with the file object
parser = PDFParser(fp)

# Create a PDF document object that stores the document structure
# Supply the password for initialization
document = PDFDocument(parser)

# Check if the document allows text extraction. If not, abort
if not document.is_extractable:
    raise PDFTextExtractionNotAllowed

# Create a PDF resource manager object that stores shared resources.
rsrcmgr = PDFResourceManager()
# Create a PDF device object.
device = PDFDevice(rsrcmgr)
# Create a PDF interpreter object.
interpreter = PDFPageInterpreter(rsrcmgr, device)
# Process each page contained in the document.
for page in PDFPage.create_pages(document):
    interpreter.process_page(page)