This commit is contained in:
2025-02-21 11:46:50 -05:00
parent 721b26ce97
commit 1bf255d0fe
12 changed files with 425 additions and 91 deletions

View File

@@ -10,7 +10,7 @@ import io
# Printer settings
printer_model = "QL-1100"
backend = 'pyusb' # Changed from network to USB
backend = 'pyusb'
printer = 'usb://0x04f9:0x20a7'
def convert_pdf_to_image(pdf_path):
@@ -45,6 +45,8 @@ def create_address_label(input_data, font_size=30, is_pdf=False):
font = ImageFont.truetype("C:\\Windows\\Fonts\\arial.ttf", size=font_size)
elif platform.system() == 'Darwin':
font = ImageFont.truetype("/Library/Fonts/Arial.ttf", size=font_size)
elif platform.system() == 'Linux':
font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/arial.ttf", size=font_size)
margin = 20
lines = input_data.split('\n')
@@ -71,10 +73,8 @@ def print_address_label(input_data, font_size=30, is_pdf=False, label_size='29x9
if not image:
raise Exception("Failed to create label image")
# For 4x6 shipping labels from Pirate Ship
if label_size == '4x6':
# Resize image to fit 4x6 format if needed
target_width = 1164 # Adjusted for 4x6 format
target_width = 1164
target_height = 1660
image = image.resize((target_width, target_height), Image.LANCZOS)
@@ -92,7 +92,6 @@ def print_address_label(input_data, font_size=30, is_pdf=False, label_size='29x9
red=False,
dpi_600=False,
hq=True,
#cut=True
cut=False
)
@@ -135,34 +134,24 @@ def process_tcg_shipping_export(file_path, require_input=False, font_size=60, pr
else:
sleep(1)
# Example usage
if __name__ == "__main__":
# Example for regular address label
address = """John Doe
123 Main Street
Apt 4B
City, State 12345"""
# Example for TCG Player export
shipping_export_file = "_TCGplayer_ShippingExport_20250201_115949.csv"
# Example for Pirate Ship PDF
pirate_ship_pdf = "C:\\Users\\joshu\\Downloads\\2025-02-10---greg-creek---9400136208070411592215.pdf"
# Choose which type to process
label_type = input("Enter label type (1 for regular, 2 for TCG, 3 for Pirate Ship): ")
if label_type == "1":
address = input("Enter the address to print: ")
preview_label(address, font_size=60)
user_input = input("Press 'p' to print the label or any other key to cancel: ")
if user_input.lower() == 'p':
print_address_label(address, font_size=60)
elif label_type == "2":
shipping_export_file = input("Enter the path to the TCG Player shipping export CSV file: ")
process_tcg_shipping_export(shipping_export_file, font_size=60, preview=False)
elif label_type == "3":
pirate_ship_pdf = input("Enter the path to the Pirate Ship PDF file: ")
process_pirate_ship_pdf(pirate_ship_pdf, preview=True)
user_input = input("Press 'p' to print the label or any other key to cancel: ")
if user_input.lower() == 'p':
process_pirate_ship_pdf(pirate_ship_pdf, preview=False)
process_pirate_ship_pdf(pirate_ship_pdf, preview=False)