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

时间:2017-03-30 13:20:23

标签: 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

1 个答案:

答案 0 :(得分:0)

pdf不是字符串 - 您必须调用其中一种方法来保存它:

SELECT * FROM [tablename] WHERE [name] LIKE '%test%' 
UNION
SELECT * FROM [tablename] WHERE [id] LIKE '%test%';

一般来说,最好进入交互式解释器并粘贴到程序中,包括pdf = ...行。然后你可以说pdf.save_to("/tmp/foo.pdf") 找出你可以用这个对象做什么。