duffy_dse
duffy_dse

Reputation: 11

How to select certain keys and corresponding values using docinfo.items() in pikepdf (python) during extraction of metadata

I am trying this code to extract metadata for a pdf There is author and then title, I want values for only author and title from the metadata ''' import pikepdf pdf = pikepdf.open(path) docinfo = pdf.docinfo for key, value in docinfo.items(): if str(key).startswith("A") == True or str(key).startswith("Ti") == True: print(key, ":", value) '''
The code runs but gives no output

Upvotes: 1

Views: 219

Answers (1)

chadp
chadp

Reputation: 135

def pdfs():
    pdf = pikepdf.open("/full/path/to/pdf.pdf")
    docinfo = pdf.docinfo
    for key, value in docinfo.items():
        print(key, ":", value)

Output:

/Producer : Name

/Title : Another name

Here's the documentation as well: https://buildmedia.readthedocs.org/media/pdf/pikepdf/latest/pikepdf.pdf

Upvotes: 1

Related Questions