Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
w2pext
plugin_dbui
Commits
80e63cda
Commit
80e63cda
authored
Nov 07, 2019
by
LE GAC Renaud
Browse files
Update controller plugin_dbui/latex2pdf to download pdf file.
parent
d27b5a57
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
23 deletions
+7
-23
controllers/plugin_dbui.py
controllers/plugin_dbui.py
+7
-12
views/plugin_dbui/latex2pdf.pdf
views/plugin_dbui/latex2pdf.pdf
+0
-11
No files found.
controllers/plugin_dbui.py
View file @
80e63cda
...
...
@@ -427,38 +427,33 @@ def latex2pdf():
os
.
chdir
(
os
.
path
.
join
(
request
.
folder
,
"private"
))
fn
=
str
(
uuid4
())
fi
=
open
(
"%s.tex"
%
fn
,
"w
b
"
)
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
():
...
...
views/plugin_dbui/latex2pdf.pdf
deleted
100644 → 0
View file @
d27b5a57
{{
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment