#!/usr/bin/env python # -*- coding: windows-1252 -*- # vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab # import os import sys ver_to_test = 3 ver_to_test = 4 ver_to_test = 2 if ver_to_test == 4: from pypdf import PdfFileReader # https://github.com/claird/PyPDF4 elif ver_to_test == 3: from PyPDF3 import PdfFileReader # https://github.com/mstamy2/PyPDF3 else: from PyPDF2 import PdfFileReader # https://github.com/py-pdf/PyPDF2 - nee https://github.com/mstamy2/PyPDF2 / https://pythonhosted.org/PyPDF2/ print('Python %s on %s' % (sys.version, sys.platform)) filename = 'title_bug.pdf' f = open(filename, 'rb') pdf = PdfFileReader(f) info = pdf.documentInfo #print(info) print('title attribute %r' % info.title) # reports None print('title getText() %r' % info.getText("/Title")) # this is what .title property calls print('title get() %r' % info.get("/Title")) # this is part of what dict[] does print('title get().getObject() %r' % info.get("/Title").getObject()) # this is what dict[] does print('/Title dict entry %r' % info['/Title']) # with test pdf works print('title attribute %r' % info.title) # Sanity check it is still None print('title Workaround %r' % (info.title or info['/Title'])) # Workaround f.close()