2017-08-07 61 views
0

我有一個熱敏打印機,我很想在收據上打印一個標誌...是否有像shutil.copyfile這樣的PNG圖像?Python發送PNG文件到默認打印機

我的代碼如下

locations = ['/dev/usb/lp0', '/dev/usb/lp1', '/dev/usb/lp2'] 
     size = locations.__len__() 
     i = 0 

     while i < size: 
      printer = locations[i] 
      try: 
       shutil.copyfile('output.txt', printer) 
       break 
      except IOError: 
       i += 1 

     if i == size: 
      logging.error('Unable to connect to the printer') 
+0

'size = len(locations)'..我們使用reportlab(https://bitbucket.org/rptlab/reportlab)來查看打印機的任何內容,但這比現在要複雜得多。 。 – thebjorn

+0

謝謝你的信息。我仍在嘗試不同的設置,但我一定會看看剛剛提到的那個。 – Soichiro

+0

也許這有幫助..? https://forums.anandtech.com/threads/command-line-image-printing-in-linux.739845/ – thebjorn

回答

0

這是我能找到解決辦法由於thebjorn

os.system("lp -o fit-to-page -o orientation-requested=3 -o media=Custom.58x210mm logo.png") 

謝謝大家。