ZelluX ZelluX - 3 months ago 10x
Python Question

Extracting titles from PDF files?

I want to write a script to rename downloaded papers with their titles automatically, I'm wondering if there is any library or tricks i can make use of? The PDFs are all generated by TeX and should have some 'formal' structures.


You could try to use pyPdf and this example.

for example:

from pyPdf import PdfFileWriter, PdfFileReader

def get_pdf_title(pdf_file_path):
    with open(pdf_file_path) as f:
        pdf_reader = PdfFileReader(f) 
        return pdf_reader.getDocumentInfo().title

title = get_pdf_title('/home/user/Desktop/my.pdf')