Commit 92ba1f48 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Restore chromium headless as default PDF renderer

parent 3b486e57
......@@ -3,6 +3,10 @@ LABEL maintainer=""
RUN apt-get update && \
apt-get install --yes chromium && \
apt-get install --yes xfonts-100dpi xfonts-75dpi xfonts-base
RUN pip install --no-cache-dir gunicorn==20.0.4
ARG uid=1000
"""PDF report rendering utilities."""
import json
import logging
import subprocess
import tempfile
from abc import ABC, abstractmethod
from datetime import datetime
from pathlib import Path
import requests
......@@ -25,8 +29,9 @@ class PDFRenderer(ABC):
)"No PDF renderer available")
return None
# fallback"Creating Chromium headless PDF renderer")
return ChromiumHeadlessPDFRenderer()
class BrowserlessPDFRenderer(PDFRenderer):
......@@ -71,3 +76,37 @@ class BrowserlessPDFRenderer(PDFRenderer):
return r.content
class ChromiumHeadlessPDFRenderer(PDFRenderer):
"""Chromium implementation."""
def render(self, url: str) -> bytes:
# Create temp file to save validation report
# This temp file will be automatically deleted on context exit
with tempfile.NamedTemporaryFile(
) as tmpfile:
tmp_pdf_report = Path(
# Use chromium headless to generate PDF from validation report page
cmd = [
result =
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
if result.returncode != 0:
output = result.stdout.decode("utf-8")
log.error("Command %r returned an error: %r", cmd, output)
raise ValueError("Erreur lors de la génération du rapport PDF")
return tmp_pdf_report.read_bytes()
Supports Markdown
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