How to loop through all the other pages and check if the same QR code is present
In my code the loop section is not working
Traceback (most recent call last):
File "C:\Users\php\PycharmProjects\newforum\new.py", line 19, in <module>
page_image = page.getPixmap().getImage()
^^^^^^^^^^^^^^
AttributeError: 'PageObject' object has no attribute 'getPixmap'
Code:
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()
In my code the loop section is not working
Traceback (most recent call last):
File "C:\Users\php\PycharmProjects\newforum\new.py", line 19, in <module>
page_image = page.getPixmap().getImage()
^^^^^^^^^^^^^^
AttributeError: 'PageObject' object has no attribute 'getPixmap'