Skip to content

Instantly share code, notes, and snippets.

@stopfaner
Created December 27, 2014 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stopfaner/9b30b2f04aa47c5fb480 to your computer and use it in GitHub Desktop.
Save stopfaner/9b30b2f04aa47c5fb480 to your computer and use it in GitHub Desktop.
import cups
from xhtml2pdf import pisa
def main():
filename = "/home/stopfan/print.pdf"
xhtml = "<h1>Test print</h1>\n"
xhtml += "<h2>This is test print</h2>\n"
xhtml += "<p><img src='/home/stopfan/image.jpg'/></p>"
pdf = pisa.CreatePDF(xhtml, file(filename, "w"))
if not pdf.err:
pdf.dest.close()
conn = cups.Connection()
printers = conn.getPrinters()
for printer in printers:
print printer, printers[printer]["device-uri"]
printer_name = printers.keys()[0]
conn.printFile(printer_name, filename, "Python_print",{})
else:
print "Unable to create file"
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment