Compare commits
No commits in common. "a37918fe114b192dde041cae3bc98a361a69e198" and "537d3725d77800e2c28da2f589a6296874c06e7b" have entirely different histories.
a37918fe11
...
537d3725d7
18
app.py
18
app.py
@ -42,21 +42,25 @@ backend = 'pyusb'
|
|||||||
printer = 'usb://0x04f9:0x20a7'
|
printer = 'usb://0x04f9:0x20a7'
|
||||||
|
|
||||||
# Convert PDF to image
|
# Convert PDF to image
|
||||||
def convert_pdf_to_images(pdf_path):
|
def convert_pdf_to_image(pdf_path):
|
||||||
"""Converts a PDF to a PIL Image"""
|
"""Converts a PDF to a PIL Image"""
|
||||||
try:
|
try:
|
||||||
# Convert PDF to image (get the first page)
|
# Convert PDF to image (get the first page)
|
||||||
images = pdf2image.convert_from_path(pdf_path)
|
images = pdf2image.convert_from_path(pdf_path)
|
||||||
if images:
|
if images:
|
||||||
return images
|
return images[0] # We will only print the first page for now
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Error converting PDF: {str(e)}")
|
app.logger.error(f"Error converting PDF: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Function to print address labels
|
# Function to print address labels
|
||||||
def print_address_label(images, pdf_path):
|
def print_address_label(pdf_path):
|
||||||
try:
|
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():
|
if 'address' in pdf_path.lower():
|
||||||
target_width = 1660
|
target_width = 1660
|
||||||
@ -76,7 +80,7 @@ def print_address_label(images, pdf_path):
|
|||||||
app.logger.info("Converting image to printer instructions...")
|
app.logger.info("Converting image to printer instructions...")
|
||||||
instructions = convert(
|
instructions = convert(
|
||||||
qlr=qlr,
|
qlr=qlr,
|
||||||
images=images,
|
images=[image], # Pass as a list with the single image
|
||||||
label='102x152',
|
label='102x152',
|
||||||
threshold=70.0,
|
threshold=70.0,
|
||||||
dither=False,
|
dither=False,
|
||||||
@ -109,11 +113,7 @@ def process_queue():
|
|||||||
break
|
break
|
||||||
# Process the file (convert and print)
|
# Process the file (convert and print)
|
||||||
app.logger.info(f"Processing file: {file_path}")
|
app.logger.info(f"Processing file: {file_path}")
|
||||||
images = convert_pdf_to_images(file_path)
|
print_address_label(file_path)
|
||||||
if images:
|
|
||||||
print_address_label(images, file_path)
|
|
||||||
else:
|
|
||||||
app.logger.error(f"Failed to convert PDF to images: {file_path}")
|
|
||||||
# Signal that the task is done
|
# Signal that the task is done
|
||||||
file_queue.task_done()
|
file_queue.task_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user