Skip to content
Advertisement

print a pdf file in python

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

Advertisement

Answer

Try this code may help:

import os

def printing_reports():
  fp = open("/path-to-file/path.txt",'r')
  for line in fp:
      os.system('lp -d HPLaserJ {0}'.format(line.strip()))

 printing_reports()

Make sure the file in every line exists.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement