I'm trying to print a docx file containing 2 images with Python but can't seem to figure this one out.
For context, it's the last part of a personal project which will be a booth where users complete a quiz, and then can print a personalized card.
Printer is a Zebra ZXP Series 3.
Here's the code I'm using:
import subprocess
from subprocess import Popen
with open("FILENAME.docx") as f:
# call the system's lpr command
p = Popen(["lpr"], stdin=f, shell=True)
output = p.communicate()[0]
It crashes the printer and makes it restart.
I found the code below which would be perfect but it is for Windows, it relies on the win32com library:
from win32com import client
import time
word = client.Dispatch("Word.Application")
def printWordDocument(filename):
word.Documents.Open(filename)
word.ActiveDocument.PrintOut()
time.sleep(2)
word.ActiveDocument.Close()
word.Quit()
Any pointers to make this work on MacOs?
Thank you!
(This is my first question, I usually find answers by doing research on this site but I'm a bit stuck with this one)