在 Python3.4 中,我使用以下代码使用 requests 库从网站打印 PDF:
with open(temp_pdf_file, 'wb') as handle:
response = requests.get(html.unescape(message['body']), stream=True)
for block in response.iter_content(1024):
handle.write(block)
cmd = '/usr/bin/lpr -P {} {}'.format(self.printer_name,temp_pdf_file)
print(cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = proc.communicate()
exit_code = proc.wait()
有没有办法直接跳过临时文件保存并直接流式传输打印机?