Commit e50e43d5 authored by Luc Grosheintz's avatar Luc Grosheintz

Only concatenate the student's attempt.

parent c08b930b
......@@ -44,12 +44,8 @@ print quality is much better than that of the D-MATH printers. Don't use the web
form for the upload, it will ask you to upload a single file, which implies that
you have to staple/sort manually. Call them by phone or write an email to
druckzentrum_hg@services.ethz.ch and agree how to send the PDFs. Recommended
printer setting is duplex (long-edge binding) and staple (top-left). You may
want to convert to 2-pages-up first using the ``pdfnup`` command, for example:
::
parallel pdfnup ::: $(ls [0-9]*.pdf)
printer setting is 2 on-one (2-up), duplex (long-edge binding) and staple
(top-left).
The print jobs sent to the Druckzentrum may take a few hours up to half a day to
complete. If you don't have time to wait, you can print the exams on one of the
......@@ -82,7 +78,7 @@ Every even page is rotated by 180°.
Additionally, other outputs are created at ``/path/to/results``:
- A single pdf-file called ``out.pdf``, which is the same as ``out_rotated.pdf`` without the rotation of even pages.
- A single pdf-file called ``out.pdf``, which is the same as ``out_rotated.pdf`` without the rotation of even pages.
The default printing settings (duplex printing, long side) already make sure that the pages of the printout are properly oriented.
- For each student a pdf-file ending with ``-nup.pdf`` is created, same as the original pdf-file from ``run.sh`` but with two sides per page.
......@@ -95,8 +91,8 @@ The default printing settings (duplex printing, long side) already make sure tha
./print.sh [--printer name] /path/to/results
The argument ``--printer`` is optional. By default the printer in front of HG
J42 will be used. It will print two-pages up with long edge bindings. You may
define your own printer options in the environment variable
J42 will be used. It will print two-pages up with long edge bindings, but no
stapling. You may define your own printer options in the environment variable
``EXAM_PRINT_OPTIONS``.
- Hint: Use ``lpstat -p`` to get a list of available printers.
......
......@@ -3,6 +3,8 @@
import copy, os, sys
from pyPdf import PdfFileWriter, PdfFileReader
from subprocess import call
import glob
import re
if len(sys.argv) < 2:
......@@ -10,36 +12,35 @@ if len(sys.argv) < 2:
else:
for (dirpath, subdirs, filenames) in os.walk(sys.argv[1]):
for filename in filenames:
if filename.lower().endswith('.pdf'):
path = os.path.join(dirpath, filename)
call([
'pdfnup', '--nup', '2x1', path, '-o',
path[:-4] + '-nup.pdf'
])
results_dir = sys.argv[1]
pdf_files = glob.glob(os.path.join(results_dir, "*.pdf"))
is_good = lambda f: re.match(r"[0-9.]+.pdf", os.path.basename(f))
pdf_files = [f for f in pdf_files if is_good(f)]
nupped_pdfs = [f[:-4] + "-nup.pdf" for f in pdf_files]
for pdf, nup in zip(pdf_files, nupped_pdfs):
call([ 'pdfnup', '--nup', '2x1', pdf, '-o', nup])
output = PdfFileWriter()
output_page_number = 0
alignment = 2 # to align on even pages
for (dirpath, subdirs, filenames) in os.walk(sys.argv[1]):
for filename in filenames:
if filename.lower().endswith('nup.pdf'):
# This code is executed for every file in turn
path = os.path.join(dirpath, filename)
input = PdfFileReader(open(path))
for p in [
input.getPage(i)
for i in range(0, input.getNumPages())
]:
# This code is executed for every input page in turn
output.addPage(p)
output_page_number += 1
while output_page_number % alignment != 0:
output.addBlankPage()
output_page_number += 1
path = os.path.join(sys.argv[1], 'out.pdf')
for path in nupped_pdfs:
# This code is executed for every file in turn
input = PdfFileReader(open(path))
pages = [input.getPage(i) for i in range(input.getNumPages())]
for p in pages:
# This code is executed for every input page in turn
output.addPage(p)
output_page_number += 1
while output_page_number % alignment != 0:
output.addBlankPage()
output_page_number += 1
path = os.path.join(results_dir, 'out.pdf')
output.write(open(path, 'w'))
pdf_in = open(path, 'r')
......@@ -52,5 +53,5 @@ else:
page.rotateClockwise(180)
pdf_writer.addPage(page)
path = os.path.join(sys.argv[1], 'out_rotated.pdf')
path = os.path.join(results_dir, 'out_rotated.pdf')
pdf_writer.write(open(path, 'w'))
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