Created
April 7, 2016 08:38
-
-
Save buptxge/2fc61a3f914645cf8ae2c9a258ca06c9 to your computer and use it in GitHub Desktop.
Print image using win32print and PIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32print | |
import win32ui | |
from PIL import Image, ImageWin | |
PHYSICALWIDTH = 110 | |
PHYSICALHEIGHT = 111 | |
printer_name = win32print.GetDefaultPrinter () | |
file_name = "new.jpg" | |
hDC = win32ui.CreateDC () | |
hDC.CreatePrinterDC (printer_name) | |
printer_size = hDC.GetDeviceCaps (PHYSICALWIDTH), hDC.GetDeviceCaps (PHYSICALHEIGHT) | |
bmp = Image.open (file_name) | |
if bmp.size[0] < bmp.size[1]: | |
bmp = bmp.rotate (90) | |
hDC.StartDoc (file_name) | |
hDC.StartPage () | |
dib = ImageWin.Dib (bmp) | |
dib.draw (hDC.GetHandleOutput (), (0,0,printer_size[0],printer_size[1])) | |
hDC.EndPage () | |
hDC.EndDoc () | |
hDC.DeleteDC () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
win32print.WritePrinter(hPrinter, raw_data + b'\n\x1D\x56\x42\x10')
solucion b'\n\x1D\x56\x42\x10')