import PyPDF2
import os
# Open the PDF file
pdf_file = open('example.pdf', 'rb')
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
# Get the content of the first page
first_page = pdf_reader.getPage(0)
content = first_page.extractText()
# Close the PDF file
pdf_file.close()
# Rename the file with its content
base_path = os.path.dirname(os.path.abspath(__file__))
new_file_name = '{}.pdf'.format(content.strip())
os.rename(os.path.join(base_path, 'example.pdf'), os.path.join(base_path, new_file_name))
#You have to have the PyPDF2 module installed so it works with you
#
#