【发布时间】:2021-04-24 04:19:40
【问题描述】:
我正在尝试使用 Latex 在 Django 项目中使用 django_tex 、 pdflatex 构建 PDF。我已经在 django setting.py 中的 INSTALLED_APPS, TEMPLATES 下进行了设置。当服务器开始运行并调用该方法时,它会在编译乳胶文件时引发错误。
Command 'cd "/tmp/tmpvk2or_tb" && pdflatex -interaction=batchmode texput.tex' returned non-zero exit status 127. 是错误。
我在 Views.py 和我的乳胶文件中附加了我的代码部分。
Views.py
from django_tex.shortcuts import render_to_pdf
template_name = 'test.tex'
context = {'content':'this is the pdf content'}
return render_to_pdf(request, 'test.tex', context, filename='test.pdf')
test.tex
\documentclass{article}
\begin{document}
\section{ {{ content }} }
\end{document}
有人可以就此提出建议吗?与使用 xhtml2pdf 相比,乳胶是生成所有背景的 pdf 的更好选择吗?
提前致谢
【问题讨论】:
-
也许你的tex模板应该包含
{{- content -}}而不是{{ content }}(注意双括号内的额外破折号),如django-tex的quick start guide的第3步? -
@Abby ,我试过了,但没用。