Untitled
unknown
plain_text
2 years ago
961 B
9
Indexable
def print_barcode(printer, barcode_image): # Get the printer DC printer_dc = win32ui.CreateDC() printer_dc.CreatePrinterDC(printer) # Get the page size and image size in pixels page_size_mm = (25.4, 54) dpi = 203 # Set the DPI value according to your printer's specification page_size_pixels = tuple(int(dpi * page_size_mm[i] / 25.4) for i in (0, 1)) image = Image.open(barcode_image) image_width, image_height = image.size # Calculate the position to center the image on the page x_pos = int((page_size_pixels[0] - image_width) / 2) y_pos = int((page_size_pixels[1] - image_height) / 2) # Start the print job printer_dc.StartDoc("barcode.png") printer_dc.StartPage() # Print the image dib = ImageWin.Dib(image) dib.draw(printer_dc.GetSafeHdc(), (x_pos, y_pos, image_width, image_height)) # End the print job printer_dc.EndPage() printer_dc.EndDoc() printer_dc.DeleteDC()
Editor is loading...