Skip to content
Snippets Groups Projects
Forked from IENT / exam-scan
21 commits behind, 129 commits ahead of the upstream repository.

exam-scan

Preparing exam scans for ship out: Adding watermarks, encryption and preparing upload to Moodle.

Contents

  • preparepdf.py unzips files from submission zip file downloadable from Moodle(in case there are no scans) and renames it accordingly in the format (_)
  • supplements.py renames and create copies of sample solutions(if any) for every student
  • watermark.py watermarks each page of PDFs containing exam scans with matriculation number of the respective student
  • encrypt.py encrypts PDF with password either with a common password(passed as an argument) or a randomly generated password(when there is no argument)
  • preparemoodle.py prepares for uploading PDFs to moodle via assign module as feedback file for each student
  • batch.py executes all three programs as a singular batch job

Please note that the three scripts watermark.py, encrypt.py, and preparemoodle.pydo not depend on each other. If you want to use only a subset (or one) of the scripts, you can find it here.

Exemplary outputs can be downloaded:

  • moodle_feedbacks.zip: The zip-Archive to be uploaded to Moodle containing the watermarked and encrypted PDFs for each student.
  • passwords.csv: CSV file containing passwords for each PDF.

Instructions

Prerequisites

  • Create and setup Moodle

    • In your Moodle course room, create an assign module following this guideline
    • Download the grading table Bewertungen.csv from Moodle via: Alle Angaben anzeigenBewertungsvorgangBewertungstabelle herunterladen
  • Create PDFs corresponding to each exam

    • Scan the exams and save the scans as PDFs (each page should be A4). For most copy machines, you can save an A3 scan (double page of an exam) as two A4 pages.
    • The filename of each PDF should start with the student's matriculation number (e.g. 123456_Nachname.pdf).
    • Place all PDFs in a folder, e.g. pdfs. ** OR: Download submission zip file**
    • Download the submission zip file from (Assignment Main Page->View all submissions->Download all submissions)
  • OR: Download submission zip file

    • Download the submission zip file from (Assignment Main Page->View all submissions->Download all submissions)
  • Optional: Create Sample Solutions (Refer here)

    • Scan the sample solutions and save the scans as PDFs (each page should be A4). For most copy machines, you can save an A3 scan (double page of an exam) as two A4 pages.
    • Place all PDFs in a folder, e.g. supplements.
  • Install the software dependancies

    The current version of code was tested on Windows10, Ubuntu 20.04.1 LTS and macOS 10.14 Mojave to ensure platform independance.The code has the following software dependencies which needs to installed before the programs can be run successfully. Specific version numbers along with categorisation based on script requirement is available here:

    • Imagemagick
    • Ghostscript
    • Python 3.8/3.9
    • PIP
    • Additional Python modules:
      • wand
      • pillow
      • PyPDF2
      • pwgen
      • pikepdf

    Instructions to install software dependencies based on your operating system:

Scripts and how to run them

Process

Run preparepdf.py (if you have submissions in a zip and not as scans) supplements.py(if you want to add watermarked sample solutions as well),watermark.py, encrypt.py, and preparemoodle.py (or run batch.py which runs all) as described in the sections below. In summary, these steps will

  1. unzip all PDF files from the zip and rename them according to the schema _
  2. prepare sample solution for each students
  3. watermark each page of each PDF with the corresponding matriculation number,
  4. encrypt each PDF with a password (global or per-student) and
  5. construct a zip-archive enabling batch upload and assignment of each PDF to each student in Moodle.

Upload moodle_feedbacks.zip to Moodle

  • Alle Angaben anzeigenBewertungsvorgangMehrere Feedbackdateien in einer Zip-Datei hochladen
  • Moodle will check for consistency and prompt errors.

Commands

Unzip submission files from and rename them

Assuming that ./submissions.zip is the zip file containing all submissions and ./Bewertungen.csv is the grading worksheet

python preparepdf.py --inzip ./submissions.zip --outfolder ./pdfs --csv ./Bewertungen.csv

or

python3 preparepdf.py --inzip ./submissions.zip --outfolder ./pdfs --csv ./Bewertungen.csv

Prepare copies of Sample Solutions for each student (Optional)

We assume that the folder ./supplements holds the scans of the sample solution.

python supplements.py

or

python3 supplements.py

Folder supplements_out contains copies of the sample solutions for each student.

Watermark the submissions

We assume that the folder ./pdfs holds the scans of the exams and . The filename of each PDF should start with the matriculation number of the student, e.g. ./pdfs/123456_Lastname.pdf.

python watermark.py --in ./pdfs --out ./pdfs_watermarked --cores 2

or

python3 watermark.py --in ./pdfs --out ./pdfs_watermarked --cores 2

Folder pdfs_watermarked contains watermarked PDFs, with each page watermarked with the matriculation number of the student.

Watermark Sample solution copies

We assume that the folder ./supplements_out holds the copies for every students

python watermark.py --in ./supplements_out --out ./pdfs_watermarked --cores 2

or

python3 watermark.py --in ./supplements_out --out ./pdfs_watermarked --cores 2

Encrypt the files

Use either a global password by specifying it with the --password option or per-student passwords by ommiting --password.

python  encrypt.py --in ./pdfs_watermarked --out ./pdfs_encrypted --password ganzgeheim

or

python3  encrypt.py --in ./pdfs_watermarked --out ./pdfs_encrypted --password ganzgeheim

Folder ./pdfs_encrypted contains all encrypted PDFs as well as passwords.csv, mapping the password of each PDF to the matriculation number.

Prepare for Moodle batch upload

This step prepares the PDFs for upload to Moodle. First, the grading table Bewertungen.csv has to be downloaded from Moodle via:

Alle Angaben anzeigenBewertungsvorgangBewertungstabelle herunterladen.

This step is needed since Moodle does not only need matriculation number, but also last and first name as well as an internal user id, which is stored in Bewertungen.csv.

python preparemoodle.py --in ./pdfs_encrypted --csv ./Bewertungen.csv --out ./moodle_feedbacks.zip

or

python3 preparemoodle.py --in ./pdfs_encrypted --csv ./Bewertungen.csv --out ./moodle_feedbacks.zip

Then, you can upload moodle_feedbacks.zip in Moodle: Alle Angaben anzeigenBewertungsvorgangMehrere Feedbackdateien in einer Zip-Datei hochladen

Further remarks:

  • Exemplary zip archive moodle_feedbacks.zip can be downloaded here.
  • You can also conduct a dry run (neither folders nor zip file are created) via ./preparemoodle.sh --dry [...]

Batch job

Or do everything in one step

python batch.py --in ./pdfs --out ./out --cores 2 --password ganzgeheim --csv ./Bewertungen.csv --supinfolder ./supplements --sup 1 --zip ./submissions.zip

or

python3 batch.py --in ./pdfs --out ./out --cores 2 --password ganzgeheim --csv ./Bewertungen.csv --supinfolder ./supplements --sup 1 --zip ./submissions.zip

with folder out containing passwords.csv and moodle_feedbacks.zip.

Original Authors

Helmut Flasche, Jens Schneider, Christian Rohlfing, IENT RWTH Aachen
Dietmar Kahlen, ITHE RWTH Aachen
Amrita Deb, IT Center, RWTH Aachen University

Who do I talk to?

Servicedesk IT-Center RWTH Aachen <servicedesk@itc.rwth-aachen.de>

If you have any errors or problems while running the programs, make sure to first check if your error is listed in FAQs