def latex2pdf(file, **kwds):
    """Render a PDF from a tex template and send it to the user."""
    import subprocess, shutil, tempfile
    PDFLATEX_BIN = 'pdflatex'
    tmpdir = tempfile.mkdtemp('smugtex')
    texfile = tmpdir + '/djangotex.tex'
    pdffile = tmpdir + '/djangotex.pdf'
    open(texfile, 'w').write(file.content)
    args = PDFLATEX_BIN, '-draftmode', '-interaction', 'batchmode', texfile
    retcode = subprocess.call(args, cwd=tmpdir)
    if retcode != 0 and retcode != 1:
        return
    args = PDFLATEX_BIN, '-interaction', 'batchmode', texfile
    retcode = subprocess.call(args, cwd=tmpdir)
    if retcode != 0 and retcode != 1:
        return
    file.content = open(pdffile, 'r').read()
    file.mimetype = 'application/pdf'
    shutil.rmtree(tmpdir)
