Created
December 27, 2014 18:11
-
-
Save stopfaner/9b30b2f04aa47c5fb480 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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