import PyPDF2
from pyzbar.pyzbar import decode
from PIL import Image
# Open the PDF file and get the first page
pdf_file = open('file.pdf', 'rb')
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
page = pdf_reader.getPage(0)
# Convert the first page to an image
page_image = page.getPixmap().getImage()
# Decode the QR code from the first page image
qr_code = decode(page_image)[0].data.decode('utf-8')
# Loop through all the other pages and check if the same QR code is present
for i in range(1, pdf_reader.getNumPages()):
page = pdf_reader.getPage(i)
page_image = page.getPixmap().getImage()
if qr_code not in [code.data.decode('utf-8') for code in decode(page_image)]:
print(f"The QR code {qr_code} is not present on page {i+1}")
break
else:
print("The QR code is present in all pages")
pdf_file.close()
Sir,some errors occur
Traceback (most recent call last):
File "c:\Users\php\PycharmProjects\newforum\new.py", line 15, in <module>
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\php\PycharmProjects\pythonwork\benv\Lib\site-packages\PyPDF2\reader.py", line 1974, in __init_
deprecation_with_replacement("PdfFileReader", "PdfReader", "3.0.0")
File "C:\Users\php\PycharmProjects\pythonwork\benv\Lib\site-packages\PyPDF2\_utils.py", line 369, in deprecation_with_replacement
deprecation(DEPR_MSG_HAPPENED.format(old_name, removed_in, new_name))
File "C:\Users\php\PycharmProjects\pythonwork\benv\Lib\site-packages\PyPDF2\_utils.py", line 351, in deprecation
raise DeprecationError(msg)
PyPDF2.errors.DeprecationError: PdfFileReader is deprecated and was removed in PyPDF2 3.0.0. Use PdfReader instead.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.