From 963a59d2d4e917b3e426fde4d974d17302a457be Mon Sep 17 00:00:00 2001 From: zman Date: Tue, 8 Apr 2025 11:08:39 -0400 Subject: [PATCH] f --- app.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 5b8ac2f..690d35b 100644 --- a/app.py +++ b/app.py @@ -42,25 +42,21 @@ backend = 'pyusb' printer = 'usb://0x04f9:0x20a7' # Convert PDF to image -def convert_pdf_to_image(pdf_path): +def convert_pdf_to_images(pdf_path): """Converts a PDF to a PIL Image""" try: # Convert PDF to image (get the first page) images = pdf2image.convert_from_path(pdf_path) if images: - return images[0] # We will only print the first page for now + return images return None except Exception as e: app.logger.error(f"Error converting PDF: {str(e)}") return None # Function to print address labels -def print_address_label(pdf_path): +def print_address_label(image, pdf_path): try: - # Convert PDF to image - image = convert_pdf_to_image(pdf_path) - if not image: - raise Exception("Failed to create label images") if 'address' in pdf_path.lower(): target_width = 1660 @@ -113,7 +109,12 @@ def process_queue(): break # Process the file (convert and print) app.logger.info(f"Processing file: {file_path}") - print_address_label(file_path) + images = convert_pdf_to_images(file_path) + if images: + for image in images: + print_address_label(image, file_path) + else: + app.logger.error(f"Failed to convert PDF to images: {file_path}") # Signal that the task is done file_queue.task_done()