如何在Python中创建PDF文件并放置LaTeX数据



我需要用一些LaTeX数据创建pdf文件。我有什么:

min_latex = (r"documentclass{article}"
         r"begin{document}"
         r"Hello, world!"
         r"end{document}")
from latex import build_pdf
# this builds a pdf-file inside a temporary directory
pdf = build_pdf(min_latex)
# look at the first few bytes of the header
print bytes(pdf)[:10]
with open('temp.pdf', 'wb+') as f:
    f.write(pdf)

但是我有以下错误消息:

File "temp.py", line 18, in <module> f.write(pdf) TypeError: argument 1 must be convertible to a buffer, not Data

pdf 不是一个字符串 - 你必须调用它的方法之一来保存它:

pdf.save_to("/tmp/foo.pdf")

一般来说,最好进入交互式解释器并粘贴到您的程序中,直到包含pdf = ...线。然后你可以说help(pdf),看看你可以用这个对象做什么。

最新更新