Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Plantilla de látex Django con imágenes

Estoy tratando de generar pdf desde la plantilla de látex de django. Para hacerlo, estoy usando el código de aquí :

Entonces tengo este código en views.py

 context = {....} template = get_template('my_latex_template.tex') rendered_tpl = template.render(context).encode('utf-8') with tempfile.TemporaryDirectory() as tempdir: for ppp in range(2): process = Popen( ['pdflatex', '-output-directory', tempdir], stdin=PIPE, stdout=PIPE, stderr=PIPE, ) process.communicate(rendered_tpl) with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f: pdf = f.read() r = HttpResponse(content_type='application/pdf') r.write(pdf)

Aquí está my_latex_template.tex

 {% autoescape on %} \documentclass[a4paper,12pt]{article} \usepackage[T1,T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[english,russian]{babel} \usepackage{graphicx} \begin{document} blabla \includegraphics{img.png} \end{document} {% endautoescape %}

La estructura de mis directorios:

 myapp |..templates |..|..my_latex_template.tex |..|..img.png |..views.py ...

Al compilar esta plantilla de látex sin \includegraphics{img.png}, todo funciona perfecto. Al compilarlo con la imagen, recibo un error que

[Errno 2] No existe tal archivo o directorio: '/var/folders/73/r8hl47ld11l68v_1kjh_m61m0000gn/T/tmprfp7wf_x/texput.pdf'

Básicamente, eso significa que este archivo temporal no se genera correctamente al ejecutar pdflatex en la plantilla renderizada...


Interesante que cuando estoy siguiendo en my_latex_template.tex

 {% autoescape on %} \documentclass[a4paper,12pt]{article} \usepackage[T1,T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[english,russian]{babel} \usepackage{graphicx} \begin{document} blabla {% endautoescape %} \includegraphics{img.png} {% autoescape on %} \end{document} {% endautoescape %}

El código se compila correctamente y obtengo un pdf, pero en lugar de una imagen , obtengo esto : la imagen no se muestra correctamente


¿Tienes alguna idea sobre qué puedo hacer? Estaría súper agradecido si alguien pudiera ayudarme.

Gracias

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!