0

I have been trying to extract the QR Code from PDF using python. When first need to see weather QR Code available in the PDF or not.

Below the Code been attached on it:

import PyPDF2
from pyzbar import pyzbar
from PIL import Image

def has_qr_code(pdf_path):
    pdf_file = open(pdf_path, 'rb')
    pdf_reader = PyPDF2.PdfReader(pdf_file)

    for page in pdf_reader.pages:
        images = page.Extract_Image()
        for image in images:
            img = Image.fromarray(image)
            decoded = pyzbar.decode(img)
            if decoded:
                return True
    
    return False

# Example usage
pdf_path = r"C:\Users\TestData.PDF"
if has_qr_code(pdf_path):
    print("QR code found in the PDF.")
else:
    print("No QR code found in the PDF.")

On page.Extract Image getting Error : "AttributeError: 'PageObject' object has no attribute 'Extract_Image'"

Suggest !!

Manish
  • 49
  • 1
  • 10
  • Does this answer your question? [Extract images from PDF without resampling, in python?](https://stackoverflow.com/questions/2693820/extract-images-from-pdf-without-resampling-in-python) – Shorn May 19 '23 at 07:25
  • based on ocumentation, either page.Extractimage() or page.extract_images(), I couldn't find extract_image in the documentation, I believe it is a deprecated function of PIL deprecated package. – Ali Massoud May 19 '23 at 08:46
  • @Shorn - Have tried with it but couldn't find the Solution. – Manish May 19 '23 at 09:37
  • @AliMassoud - Can you please suggest what alternate we can use for it. – Manish May 19 '23 at 11:04

0 Answers0