Commit 80e63cda authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update controller plugin_dbui/latex2pdf to download pdf file.

parent d27b5a57
......@@ -427,38 +427,33 @@ def latex2pdf():
os.chdir(os.path.join(request.folder, "private"))
fn = str(uuid4())
fi = open("%s.tex" % fn, "wb")
fi = open("%s.tex" % fn, "w")
fi.write(latex_string)
fi.close()
# convert the latex file into pdf
# convert the latex file into PDF
# run latex twice for longtable, ...
cmd = ["pdflatex", "-interaction", "nonstopmode", "%s.tex" % fn]
call(cmd, stdout=TemporaryFile())
call(cmd, stdout=TemporaryFile())
# clean latex processing
for ext in ("aux", "log", "tex"):
for ext in ("aux", "log", "out", "tex"):
f = "%s.%s" % (fn, ext)
if os.path.exists(f):
os.remove(f)
# dummy pdf if latex processing failed
# inform user when latex processing failed
pdf = "%s.pdf" % fn
if not os.path.exists(pdf):
return "Empty PDF file since LaTeX processing failed."
# copy the pdf file into a string an clean
fi = open(pdf, "rb")
pdf_string = fi.read()
fi.close()
os.remove(pdf)
# go back to the web2py main directory
os.chdir(cwd)
return dict(data=pdf_string)
# download the PDF file
path_pdf = os.path.join(request.folder, "private", pdf)
return response.stream(path_pdf)
def status():
......
{{
try:
response.headers['Content-Type']='application/pdf'
response.headers['Content-Disposition']='attachment;filename="latex2pdf.pdf"'
response.write(data, escape=False)
except:
raise HTML(405, T('LaTeX to PDF conversion failed.'))
}}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment