I want to print a pdf file in python. My code is as below:
def printing_reports():
import os
fp = open("/path-to-file/path.txt",'r')
for line in fp:
os.system('lp -d HPLaserJ %s' % (str(line)))
I am on Fedora 20. path.txt is a file that contain path to the pdf file like '/home/user/a.pdf'
When I run the code it says no such file or directory.
Thanks
Old question, but as I needed a an answer of how to print a pdf file from python, I found this answer more profound:
import cups
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = printers.keys()[0]
ppd_options = {}
cups_job_id = conn.printFile(printer_name,'/path/to/a.pdf',"Title printjob", ppd_connection_options)
It uses the pycups module, which needs CUPS >= 1.7 installed on your system (according to their GitHub page)
The ppd_options dictionary might just be empty. (PPD - Postscript Printer Driver)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With