Commit af7f8699 authored by Richard's avatar Richard

switched to save with even pages implementation

parent 4d68d0ea
......@@ -10,7 +10,7 @@ from werkzeug.datastructures import FileStorage
from sqlalchemy.orm import selectinload
from ..pdf_generation import generate_pdfs, output_pdf_filename_format, join_pdfs
from ..pdf_generation import page_is_size, make_pages_even, PAGE_FORMATS
from ..pdf_generation import page_is_size, save_with_even_pages, PAGE_FORMATS
from ..database import db, Exam, ExamWidget, Submission, token_length
......@@ -271,9 +271,7 @@ class Exams(Resource):
pdf_path = os.path.join(exam_dir, 'exam.pdf')
os.makedirs(exam_dir, exist_ok=True)
even_pdf = make_pages_even(args['pdf'])
even_pdf.write(pdf_path)
save_with_even_pages(pdf_path, args['pdf'])
print(f"Added exam {exam.id} (name: {exam_name}, token: {exam.token}) to database")
......
......@@ -407,17 +407,21 @@ def page_is_size(exam_pdf_file, shape, tolerance=0):
return not invalid
def make_pages_even(exam_pdf_file):
def save_with_even_pages(pdf_path, exam_pdf_file):
exam_pdf = PdfReader(exam_pdf_file)
new = PdfWriter()
new.addpages(exam_pdf.pages)
pagecount = len(exam_pdf.pages)
if (pagecount % 2 == 1):
blank = PageMerge()
box = exam_pdf.pages[0].MediaBox
blank.mbox = box
blank = blank.render()
new.addpage(blank)
if (pagecount % 2 == 0):
exam_pdf_file.save(pdf_path)
return
new = PdfWriter()
new.addpages(exam_pdf.pages)
blank = PageMerge()
box = exam_pdf.pages[0].MediaBox
blank.mbox = box
blank = blank.render()
new.addpage(blank)
return new
new.write(pdf_path)
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