Keegan Skeate
Keegan Skeate

Reputation: 31

How do you get the filename from a `pdfplumber.pdf.PDF`?

I have a function that is passed a pdfplumber.pdf.PDF argument and I need to reference the filename of the PDF. Is there any way to get the filename from a pdfplumber.pdf.PDF class instance?

Upvotes: 0

Views: 450

Answers (1)

Keegan Skeate
Keegan Skeate

Reputation: 31

Yes, if pdf is a pdfplumber.pdf.PDF, then you can easily find the filename:

import pdfplumber

pdf = pdfplumber.open('your.pdf')
filename = pdf.stream.name
print(filename)

Upvotes: 1

Related Questions