【问题标题】:Using Latex in Django project with django_tex , pdflatex在 Django 项目中使用 Latex 和 django_tex , pdflatex
【发布时间】: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 ,我试过了,但没用。

标签: django pdf latex pdflatex


【解决方案1】:

尝试将代码放入设置中 LATEX_INTERPRETER = 'pdflatex' 看看能不能解决。

【讨论】:

  • 您应该将此添加为评论而不是答案或自己提出问题
  • 感谢您告诉我,我更改了答案。拥抱!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 2011-05-03
  • 1970-01-01
  • 2012-06-04
  • 2015-12-04
相关资源
最近更新 更多