在 python 中打印 pdf 文件

print a pdf file in python

我想在 python 中打印一个 pdf 文件。我的代码如下:

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)))

我在 Fedora 20 上。path.txt 是一个包含 pdf 文件路径的文件,如“/home/user/a.pdf” 当我 运行 代码时,它说没有这样的文件或目录。

谢谢

试试这个代码可能会有帮助:

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()

确保每一行中的文件都存在。