GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing thepythoncode.com — How to Extract PDF Metadata in Python - The Python Code Before we get started, have you tried our new Python Code Assistant? It's like having an expert coder at your fingertips. Check it out! The metadata in PDFs is useful information about the PDF document, it includes the title of the document, the author, last modification date, creation date, subject, and much more. Some PDF files got more information than others, and in this tutorial, you will learn how to extract PDF metadata in Python. There are a lot of libraries and utilities in Python to accomplish the same thing but I like using pikepdf, as it's an active and maintained library. Let's install it:
Pikepdf is a Pythonic wrapper around the C++ QPDF library. Let's import it in our script:
We'll also use the sys module to get the filename from the command-line arguments:
Let's load the PDF file using the library, and get the metadata:
The
Output:
Related: How to Split PDF Files in Python. Here is another PDF file:
Output:
As you can see, not all documents have the same fields, some contain much less information. Notice that the
Here is the same output previously, but with datetime formats converted to Python datetime objects:
Get Our Practical Python PDF Processing EBookMaster PDF Manipulation with Python by building PDF tools from scratch. Get your copy now! Download EBookMuch better. I hope this quick tutorial helped you to get the metadata of PDF documents with Python. Check the complete code here. Here are some PDF-related tutorials:
For more PDF handling guides on Python, you can check our Practical Python PDF Processing EBook, where we dive deeper into PDF document manipulation with Python, make sure to check it out here if you're interested! Learn also: How to Extract Image Metadata in Python Happy coding ♥ Liked what you read? You'll love what you can learn from our AI-powered Code Explainer. Check it out!
Sharing is caring!
Read also
How to Extract Video Metadata in PythonLearn how to extract video or audio file metadata in Python with the help of ffmpeg framework and its ffmpeg-python wrapper. How to Extract Images from PDF in PythonLearn how to extract and save images from PDF files in Python using PyMuPDF and Pillow libraries.
How to Extract Text from Images in PDF Files with PythonLearn how to leverage tesseract, OpenCV, PyMuPDF and many other libraries to extract text from images in PDF files with Python CommentsGot a coding query or need some guidance before you comment? Check out this Python Code Assistant for expert advice and handy tips. It's like having a coding tutor right in your fingertips! |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |