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 (<Matriculation number>_<Lastname>
) -
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.py
do 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 anzeigen
→Bewertungsvorgang
→Bewertungstabelle herunterladen
- In your Moodle course room, create an
-
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
If you are an experienced user and familiar with the python
venv
(virtual environments) module and after having installed both ImageMagick (beware thePolicy Error
fix in FAQs)and Ghostscript you can install the python dependencies in the virtual environment via pip withpython -m venv venv source venv/bin/activate pip install -r requirements.txt python ./watermark.sh --help
The current version of code was tested on Windows10, Ubuntu 20.04.1 LTS and macOS 10.14 Mojave to ensure platform independence.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:
- Windows 10 : Installation of Software Dependencies
- MacOS : Installation of Software Dependencies
- Linux : Installation of Software Dependencies
Docker
If you are an experienced user familiar with Docker, you can use the provided Dockerfile
to easily run the scripts.
Either use the already built image
docker run --name='examscan' --rm -v $(pwd):$(pwd) -w $(pwd) registry.git.rwth-aachen.de/rwthmoodle/exam-scan:master batch.py --help
or build the Dockerfile yourself locally
docker build -t examscan:latest .
docker run --name examscan --rm -v $(pwd):$(pwd) -w $(pwd) examscan:latest batch.py --help
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
- unzip all PDF files from the zip and rename them according to the schema
<Matriculation number>_<Lastname>
- prepare sample solution for each students
- watermark each page of each PDF with the corresponding matriculation number,
- encrypt each PDF with a password (global or per-student) and
- 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 anzeigen
→Bewertungsvorgang
→Mehrere Feedbackdateien in einer Zip-Datei hochladen
- Moodle will check for consistency and prompt errors.
Commands
Please note that the following commands may only work for you with either python
or python3
.
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
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
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
Folder pdfs_watermarked
contains watermarked PDFs, with each page watermarked with the matriculation number of the student.
TIP: Play around with dpi
and quality
parameters according to your requirements. Higher values for these two will result in high resolution PDFs of bigger size (ideal for when the number of files is low). Lower values will result in PDFs having lower file size and low resolution (ideal when the number of files is high)
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
Encrypt the files
Use either a global password by specifying it with the --password
option or per-student passwords by omitting --password
.
python 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 anzeigen
→ Bewertungsvorgang
→ Bewertungstabelle 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
Then, you can upload moodle_feedbacks.zip
in Moodle:
Alle Angaben anzeigen
→ Bewertungsvorgang
→ Mehrere 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
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