DEV Community

Cover image for Exploring PDF Metadata with PyMuPDF
PDF Python Hub
PDF Python Hub

Posted on Originally published at payhip.com

Exploring PDF Metadata with PyMuPDF

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
Enter fullscreen mode Exit fullscreen mode

This takes the metadata associated with doc and stores it in a variable called metadata.

2. Print the metadata

print(metadata)
Enter fullscreen mode Exit fullscreen mode

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"])
Enter fullscreen mode Exit fullscreen mode

Complete Example

metadata = doc.metadata

print(metadata)
Enter fullscreen mode Exit fullscreen mode

Open the notebook

Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.

[Open in Google Colab]


To open your first PDF file with PyMuPDF, check out this mini-guide: Open Your First PDF with PyMuPDF.

Top comments (0)