pdf backup
This commit is contained in:
@@ -346,19 +346,21 @@ def print_to_printer(printer_name, file_path):
|
|||||||
def print_label_standalone(value, printer, preview=0, use_pdf=True):
|
def print_label_standalone(value, printer, preview=0, use_pdf=True):
|
||||||
"""
|
"""
|
||||||
Print a label with the specified text on the specified printer.
|
Print a label with the specified text on the specified printer.
|
||||||
|
Always generates a PDF backup in pdf_backup and prints that PDF.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
value (str): The text to print on the label
|
value (str): The text to print on the label
|
||||||
printer (str): The name of the printer to use
|
printer (str): The name of the printer to use
|
||||||
preview (int): 0 = no preview, 1-3 = 3s preview, >3 = 5s preview
|
preview (int): 0 = no preview, 1-3 = 3s preview, >3 = 5s preview
|
||||||
use_pdf (bool): True to use PDF (recommended for quality), False for PNG
|
use_pdf (bool): False to also generate a PNG if PDF generation fails
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if printing was successful, False otherwise
|
bool: True if printing was successful, False otherwise
|
||||||
"""
|
"""
|
||||||
# For tracking if file was created
|
# Track generated files
|
||||||
file_created = False
|
file_created = False
|
||||||
temp_file = None
|
temp_file = None
|
||||||
|
pdf_file = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Debug output
|
# Debug output
|
||||||
@@ -366,20 +368,33 @@ def print_label_standalone(value, printer, preview=0, use_pdf=True):
|
|||||||
print(f"Preview type: {type(preview)}")
|
print(f"Preview type: {type(preview)}")
|
||||||
print(f"Using format: {'PDF' if use_pdf else 'PNG'}")
|
print(f"Using format: {'PDF' if use_pdf else 'PNG'}")
|
||||||
|
|
||||||
# Create label in selected format
|
# Always generate a PDF backup and print that PDF for verification
|
||||||
if use_pdf:
|
try:
|
||||||
temp_file = create_label_pdf(value)
|
pdf_file = create_label_pdf(value)
|
||||||
print(f"PDF label created: {temp_file}")
|
if pdf_file and os.path.exists(pdf_file):
|
||||||
print(f"PDF backup saved to: {temp_file}")
|
print(f"PDF label created: {pdf_file}")
|
||||||
|
print(f"PDF backup saved to: {pdf_file}")
|
||||||
|
else:
|
||||||
|
print("PDF generation returned no file path")
|
||||||
|
except Exception as pdf_err:
|
||||||
|
print(f"PDF generation failed: {pdf_err}")
|
||||||
|
|
||||||
|
# Optionally also create the label image (PNG)
|
||||||
|
if not pdf_file or not os.path.exists(pdf_file):
|
||||||
|
if not use_pdf:
|
||||||
|
label_img = create_label_image(value)
|
||||||
|
temp_file = 'final_label.png'
|
||||||
|
label_img.save(temp_file)
|
||||||
|
print(f"PNG label created: {temp_file}")
|
||||||
else:
|
else:
|
||||||
# Create the label image (PNG)
|
temp_file = pdf_file
|
||||||
label_img = create_label_image(value)
|
|
||||||
temp_file = 'final_label.png'
|
|
||||||
label_img.save(temp_file)
|
|
||||||
print(f"PNG label created: {temp_file}")
|
|
||||||
|
|
||||||
file_created = True
|
file_created = True
|
||||||
|
|
||||||
|
if not temp_file or not os.path.exists(temp_file):
|
||||||
|
print("No label file created for printing")
|
||||||
|
return False
|
||||||
|
|
||||||
# Convert preview to int if it's a string
|
# Convert preview to int if it's a string
|
||||||
if isinstance(preview, str):
|
if isinstance(preview, str):
|
||||||
preview = int(preview)
|
preview = int(preview)
|
||||||
@@ -417,8 +432,8 @@ def print_label_standalone(value, printer, preview=0, use_pdf=True):
|
|||||||
|
|
||||||
finally:
|
finally:
|
||||||
# This block always executes, ensuring cleanup
|
# This block always executes, ensuring cleanup
|
||||||
if use_pdf:
|
if pdf_file and os.path.exists(pdf_file):
|
||||||
print(f"Cleanup complete - PDF backup saved to pdf_backup folder")
|
print("Cleanup complete - PDF backup saved to pdf_backup folder")
|
||||||
else:
|
else:
|
||||||
print("Cleanup complete - label file retained for reference")
|
print("Cleanup complete - label file retained for reference")
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
COM-2024-002;ART-67890;SN-20260212-TEST
|
COM-2024-002;ART-67890;SN-20260212
|
||||||
Reference in New Issue
Block a user