If you’re working with a PyMuPDF's Document object called doc, you can access its metadata with:
metadata = doc.metadata
PyMuPDF is a Python library for working with PDF files.
What does doc.metadata mean?
doc.metadata contains additional information about the PDF document, rather than the PDF document’s main text.
It might contain information such as:
- format
- title
- author
- creator
1. Store the metadata
metadata = doc.metadata
This takes the metadata associated with doc and stores it in a variable called metadata.
2. Print the metadata
print(metadata)
This displays the metadata:
{'format': 'PDF 1.5', 'title': 'Artificial Intelligence (AI) ', 'author': 'PDF Python Hub', 'subject': 'An Overview of Artificial Intelligence, Machine Learning, Generative AI, Ethical Frameworks, and Future Outlook', 'keywords': 'Artificial Intelligence, AI, Machine Learning, Deep Learning, Generative AI, Large Language Models, AI Ethics', 'creator': 'Google Docs', 'producer': 'Skia/PDF m153 Google Docs Renderer', 'creationDate': "D:20260816101230+02'00'", 'modDate': "D:20260818145823+02'00'", 'trapped': '', 'encryption': None}
You can then access individual pieces of information:
print(metadata["author"])
print(metadata["creationDate"])
Complete Example
metadata = doc.metadata
print(metadata)
Open the notebook
Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.
To open your first PDF file with PyMuPDF, check out this mini-guide: Open Your First PDF with PyMuPDF.
Top comments (0)