Extract the text from a PDF document, e.g. to add PDF text
    content to an index for searching.

    To use on a file, the syntax is:
        text = pdf_to_text(open(pdf_filepath, 'rb'))

    To use on a datastream from EULFedora, the syntax is:
        pdfobj = repository.get_object(pid)
        text = pdf_to_text(pdfobj.pdf.content)

    :param pdfstream: A file-like object that supports read and seek
        methods, as required by :class:`pyPdf.PdfFileReader`

def pdf_to_text(pdfstream):
    '''Extract the text from a PDF document, e.g. to add PDF text
    content to an index for searching.

    To use on a file, the syntax is:
        text = pdf_to_text(open(pdf_filepath, 'rb'))

    To use on a datastream from EULFedora, the syntax is:
        pdfobj = repository.get_object(pid)
        text = pdf_to_text(pdfobj.pdf.content)

    :param pdfstream: A file-like object that supports read and seek
        methods, as required by :class:`pyPdf.PdfFileReader`

    '''
    pdfreader = PdfFileReader(pdfstream)
    if pdfreader.isEncrypted:
        raise Exception('Cannot extract text from encrypted PDF documents')
    return '\n'.join([page.extractText() for page in pdfreader.pages])