Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
205dc4a2
Verified
Commit
205dc4a2
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Use a headless Chromium instead of electron-pdf
parent
4a76e450
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!464
Resolve "Support PDF generation via a headless Chromium running in the background using celery"
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Dockerfile
+1
-24
1 addition, 24 deletions
Dockerfile
aleksis/core/static/print.css
+1
-0
1 addition, 0 deletions
aleksis/core/static/print.css
aleksis/core/util/pdf.py
+27
-4
27 additions, 4 deletions
aleksis/core/util/pdf.py
docs/dev/01_setup.rst
+1
-5
1 addition, 5 deletions
docs/dev/01_setup.rst
with
30 additions
and
33 deletions
Dockerfile
+
1
−
24
View file @
205dc4a2
...
...
@@ -33,30 +33,7 @@ RUN apt-get -y update && \
libssl-dev
\
postgresql-client
\
yarnpkg
\
xvfb
\
x11-xkb-utils
\
xfonts-100dpi
\
xfonts-75dpi
\
xfonts-scalable
\
xfonts-cyrillic
\
x11-apps
\
clang
\
libdbus-1-dev
\
libgtk2.0-dev
\
libnotify-dev
\
gnome-keyring
\
libgconf2-dev
\
libasound2-dev
\
libcap-dev
\
libcups2-dev
\
libxtst-dev
\
libxss1
\
libnss3-dev
\
gcc-multilib
\
libgbm-dev
\
xauth
\
g++-multilib
&&
\
eatmydata yarnpkg global add electron-pdf
&&
\
chromium
&&
\
eatmydata pip
install
uwsgi
# Install extra dependencies
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/static/print.css
+
1
−
0
View file @
205dc4a2
...
...
@@ -5,6 +5,7 @@
@page
{
size
:
A4
;
padding
:
30mm
;
margin
:
0
;
}
header
{
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/util/pdf.py
+
27
−
4
View file @
205dc4a2
...
...
@@ -2,11 +2,13 @@ import glob
import
os
import
subprocess
# noqa
from
tempfile
import
TemporaryDirectory
from
typing
import
Optional
from
django.http.request
import
HttpRequest
from
django.http.response
import
HttpResponse
from
django.shortcuts
import
render
from
django.template.loader
import
render_to_string
from
django.utils.translation
import
get_language
from
django.utils.translation
import
gettext
as
_
from
celery_progress.backend
import
ProgressRecorder
...
...
@@ -18,7 +20,9 @@ from aleksis.core.util.core_helpers import path_and_rename
@recorded_task
def
generate_pdf
(
html_code
:
str
,
pdf_path
:
str
,
recorder
:
ProgressRecorder
):
def
generate_pdf
(
html_code
:
str
,
pdf_path
:
str
,
recorder
:
ProgressRecorder
,
lang
:
Optional
[
str
]
=
None
):
"""
Generate a PDF file by rendering the HTML code using electron-pdf.
"""
recorder
.
set_progress
(
0
,
1
)
...
...
@@ -29,8 +33,25 @@ def generate_pdf(html_code: str, pdf_path: str, recorder: ProgressRecorder):
with
open
(
path
,
"
w
"
)
as
f
:
f
.
write
(
html_code
)
# Start a X framebuffer and run electron-pdf
subprocess
.
run
([
"
xvfb-run
"
,
"
-a
"
,
"
electron-pdf
"
,
path
,
pdf_path
])
# noqa
lang
=
lang
or
get_language
()
# Run PDF generation using a headless Chromium
cmd
=
[
"
chromium
"
,
"
--headless
"
,
"
--no-sandbox
"
,
"
--run-all-compositor-stages-before-draw
"
,
"
--temp-profile
"
,
"
--disable-dev-shm-usage
"
,
"
--disable-gpu
"
,
"
--disable-setuid-sandbox
"
,
"
--dbus-stub
"
,
f
"
--home-dir=
{
temp_dir
}
"
,
f
"
--lang=
{
lang
}
"
,
f
"
--print-to-pdf=
{
pdf_path
}
"
,
f
"
file://
{
path
}
"
,
]
subprocess
.
run
(
cmd
)
# noqa
recorder
.
set_progress
(
1
,
1
)
...
...
@@ -52,7 +73,9 @@ def render_pdf(request: HttpRequest, template_name: str, context: dict = None) -
html_template
=
render_to_string
(
template_name
,
context
)
result
=
generate_pdf
.
delay
(
html_template
,
os
.
path
.
join
(
MEDIA_ROOT
,
pdf_path
))
result
=
generate_pdf
.
delay
(
html_template
,
os
.
path
.
join
(
MEDIA_ROOT
,
pdf_path
),
lang
=
get_language
()
)
context
=
{
"
title
"
:
_
(
"
Progress: Generate PDF file
"
),
...
...
This diff is collapsed.
Click to expand it.
docs/dev/01_setup.rst
+
1
−
5
View file @
205dc4a2
...
...
@@ -28,11 +28,7 @@ Install native dependencies
Some system libraries are required to install AlekSIS::
sudo apt install build-essential libpq-dev libpq5 libssl-dev python3-dev python3-pip python3-venv yarnpkg gettext xvfb
Additionally, you have to install ``electron-pdf`` for the PDF rendering feature using ``npm``::
sudo yarn global add electron-pdf
sudo apt install build-essential libpq-dev libpq5 libssl-dev python3-dev python3-pip python3-venv yarnpkg gettext chromium
Get Poetry
----------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment