I've indirectly read about tagged PDFs in TabbyPDF: Web-Based System for PDF Table Extraction where it sounds as if one could get semantic information of an PDFs content. So not only author / title / number of pages, but maybe something like sections or where a title is.
Is this possible?
Here are some example PDFs to show, in case it is:
What I've tried
I might go in the completely wrong direction, but the kind of information I get is only metadata of the document. Not of its content / the contents structure. I was hoping for something like semantic HTML elements that I would know that there are two sections, one table, three paragraphs. Maybe even that the table has a caption and 42 rows and 123 columns.
PyPDF2
from PyPDF2 import PdfFileReader
def get_info(path):
with open(path, "rb") as f:
pdf = PdfFileReader(f)
info = pdf.getDocumentInfo()
nb_pages = pdf.getNumPages()
info = dict(info)
info['nb_pages'] = nb_pages
return info
if __name__ == "__main__":
path = "PDF-export-example.pdf"
info = get_info(path)
for key, value in sorted(info.items()):
print(f"{key:<15}: {value}")
Lorem Ipsum Table Test:
/Author : Martin Thoma
/CreationDate : D:20200730020133-07'00'
/Creator : Microsoft Word
/ModDate : D:20200730020133-07'00'
nb_pages : 1
Camelot Edge TOL:
/Producer : PyPDF2
nb_pages : 1
pdfminer
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
def get_info(path):
with open(path, "rb") as f:
parser = PDFParser(f)
doc = PDFDocument(parser)
return doc.info
if __name__ == "__main__":
path = "edge_tol.pdf"
info = get_info(path)
for el in info:
for key, value in el.items():
print(f"{key:<15}: {value}")
Lorem Ipsum Table Test:
Author : b'Martin Thoma'
Creator : b'Microsoft Word'
CreationDate : b"D:20200730020133-07'00'"
ModDate : b"D:20200730020133-07'00'"
Camelot Edge TOL:
Producer : b'PyPDF2'