Create Pdf with Latex in django

There is simple steps with help you make pdf using Latex and django

  • First create view
  • Create the file with help open() and write function
  • Write the data in file which you created
  • Make Latex file as your template
  • Now perform  the  rendering according your references which are stored in Latex template file
  • After this run call function with help you call the bash script with your latex file to pdf file is created.


  {{ content }}


import os
from django.shortcuts import render, render_to_response, RequestContext, HttpResponseRedirect
from django.core.files import File
from django.template.loader import render_to_string
from subprocess import call
def home(request):
texfilename = "filepath"
texfilename_copy = "second_filepath"
f = open(texfilename ,'r+')
#cfile = file(texfilename, 'w+')
data =
fw = open(texfilename_copy, 'w+')
texfile =, os.O_RDWR)
os.write(texfile, render_to_string('filepath_second ', {'content':'hitesh softa'}))
return render(request, 'my_latex_tamplate.tex', context_instance =RequestContext(request))

Now make your Bash script file with help of editor and add this code in this script

cd [template file path]
pdflatex [filename]

rm -f *.log

rm -f *.aux

One Comment Add yours

  1. hero4indians says:

    Can you explain a little bit more what is happening in

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s