【发布时间】:2016-09-12 14:55:24
【问题描述】:
我将生成一系列pdf文件,其内容将在Python(2.7)中生成。常规解决方案是将 .tex 内容保存在某个目录中,在文件上调用 pdflatex,然后读取 pdf 文件,以便最终将文件放在相关的位置。如下所示:
import os
texFile = \
"""\\documentclass[11pt,a4paper,final]{article}
\\begin{document}
Hello, world!
\\end{document}
""" # Clearly will a more awesome file be generated here!
with open('hello.tex', 'w') as f:
f.write(texFile)
os.system('pdflatex hello.tex')
pdfFile = open('hello.pdf', 'rb').read()
# Now place the file somewhere relevant ...
我想要相同的程序,但在内存中进行,以提高速度并避免文件泄漏到某些文件夹中。所以我的问题是,如何在内存中运行 pdflatex 并将生成的 pdf 提取回 Python?
【问题讨论】: