Commit d06e7f2c authored by Hugo Kerstens's avatar Hugo Kerstens
Browse files

Use reportlab for generation solution pdf

parent 5dcde227
......@@ -8,10 +8,12 @@ from email.mime.base import MIMEBase
from email import encoders
import jinja2
from wand.image import Image
from reportlab.pdfgen import canvas
from .database import Submission
from . import statistics
from .api.exams import PAGE_FORMATS
def solution_pdf(exam_id, student_id):
......@@ -20,17 +22,17 @@ def solution_pdf(exam_id, student_id):
pages = sorted((p for s in subs for p in s.pages), key=(lambda p: p.number))
pages = [p.path for p in pages]
with Image() as output_pdf:
for filepath in pages:
with Image(filename=filepath) as page:
output_pdf.format = 'pdf'
result = BytesIO()
from flask import current_app
page_format = current_app.config.get('PAGE_FORMAT', 'A4') # TODO Remove default value
page_size = PAGE_FORMATS[page_format]
result = BytesIO()
pdf = canvas.Canvas(result, pagesize=page_size)
for page in pages:
pdf.drawImage(page, 0, 0, width=page_size[0], height=page_size[1])
return result
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