1

I need to create pdf file with some LaTeX data. What I have:

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)

But I have the following error message:

File "temp.py", line 18, in <module> f.write(pdf) TypeError: argument 1 must be convertible to a buffer, not Data
2
  • Explain the errors, give us the log/ error message... Commented Mar 30, 2017 at 13:29
  • @Kartoch here's error:Traceback (most recent call last): File "temp.py", line 18, in <module> f.write(pdf) TypeError: argument 1 must be convertible to a buffer, not Data Commented Mar 30, 2017 at 13:32

1 Answer 1

1

pdf is not a string - you have to invoke one of its methods to save it:

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

In general, it's a good idea to go into the interactive interpreter and paste in your program up to including the pdf = ... line. Then you can say help(pdf) to find out what you can do with that object.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this little tip! It's absolutely awesome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.