Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
4ab0dad1
Commit
4ab0dad1
authored
Aug 15, 2018
by
Hugo LEVY-FALK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documentation propre de render_tex et create_pdf
parent
9dd54a99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
cotisations/tex.py
cotisations/tex.py
+22
-6
No files found.
cotisations/tex.py
View file @
4ab0dad1
...
...
@@ -62,15 +62,23 @@ def render_invoice(_request, ctx={}):
def
create_pdf
(
template
,
ctx
=
{}):
"""
Creates and returns a PDF from a LaTeX template using pdflatex.
"""Creates and returns a PDF from a LaTeX template using pdflatex.
It create a temporary file for the PDF then read it to return its content.
Args:
template: Path to the LaTeX template.
ctx: Dict with the context for rendering the template.
Returns:
The content of the temporary PDF file generated.
"""
context
=
Context
(
ctx
)
template
=
get_template
(
template
)
rendered_tpl
=
template
.
render
(
context
).
encode
(
'utf-8'
)
with
tempfile
.
TemporaryDirectory
()
as
tempdir
:
for
i
in
range
(
2
):
for
_
in
range
(
2
):
process
=
Popen
(
[
'pdflatex'
,
'-output-directory'
,
tempdir
],
stdin
=
PIPE
,
...
...
@@ -84,10 +92,18 @@ def create_pdf(template, ctx={}):
def
render_tex
(
_request
,
template
,
ctx
=
{}):
"""
Creates a PDF from a LaTex templates using pdflatex.
Writes it in a temporary directory
and send back an HTTP response for
"""
Creates a PDF from a LaTex templates using pdflatex.
Calls `create_pdf`
and send back an HTTP response for
accessing this file.
Args:
_request: Unused, but allow using this function as a Django view.
template: Path to the LaTeX template.
ctx: Dict with the context for rendering the template.
Returns:
An HttpResponse with type `application/pdf` containing the PDF file.
"""
pdf
=
create_pdf
(
template
,
ctx
=
{})
r
=
HttpResponse
(
content_type
=
'application/pdf'
)
...
...
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