[英]How to create PDF file in Python and put LaTeX data?
我需要用一些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)
来找出你可以用这个对象做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.