Commit 792b1661 authored by Daniele Casati's avatar Daniele Casati

changed orientation

parent 5bb9b964
......@@ -2,7 +2,7 @@ USAGE
=====
Wrapper scripts ``run.sh``, ``concatenate.py`` and ``print.sh``
-----------------------------------
---------------------------------------------------------------
0) Follow the instructions for installation first: `HOW TO INSTALL`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -32,15 +32,20 @@ see. ``./run.sh --help``.
./concatenate.py /path/to/results
The output is a single pdf-file called ``out.pdf``,
The main output is a single pdf-file called ``out_rotated.pdf``,
which will be saved at ``/path/to/results``.
This file contains all students' exams.
Each page includes two sides of the original pdf-files.
Blank pages are added so that the exam of each students starts with an odd page number.
``out.pdf`` is in a conventient format for printing, as the sheets of the individual exams can be separated without overlaps.
Every even page is rotated by 180°.
Additionally, for each student a pdf-file ending with ``-nup.pdf``
is created at ``/path/to/results``, with two sides per page.
``out_rotated.pdf`` is in a conventient format for printing, as the sheets of the individual exams can be separated without overlaps.
Furthermore, the default printing settings (duplex printing, long side) already make sure that the pages of the printout are properly oriented.
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.
- 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.
2b) Alternatively, send all the individual PDFs to a printer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -4,26 +4,27 @@ import copy, os, sys
from pyPdf import PdfFileWriter, PdfFileReader
from subprocess import call
output = PdfFileWriter()
output_page_number = 0
if len(sys.argv) < 2:
print('Please pass path to results')
else:
for (dirpath, dirnames, filenames) in os.walk(sys.argv[1]):
for (dirpath, subdirs, filenames) in os.walk(sys.argv[1]):
for filename in filenames:
if filename.lower().endswith('.pdf'):
call(['pdfnup', '--nup', '2x1', filename])
path = os.path.join(dirpath, filename)
call(['pdfnup', '--nup', '2x1', path, '-o', path[:-4]+'-nup.pdf'])
output = PdfFileWriter()
output_page_number = 0
alignment = 2 # to align on even pages
for (dirpath, dirnames, filenames) in os.walk(sys.argv[1]):
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
input = PdfFileReader(open(filename))
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)
......@@ -32,5 +33,19 @@ else:
output.addBlankPage()
output_page_number += 1
sys.stdout = open('out.pdf', 'w')
output.write(sys.stdout)
path = os.path.join(sys.argv[1], 'out.pdf')
output.write(open(path, 'w'))
pdf_in = open(path, 'r')
pdf_reader = PdfFileReader(pdf_in)
pdf_writer = PdfFileWriter()
for pagenum in range(pdf_reader.numPages):
page = pdf_reader.getPage(pagenum)
if pagenum % 2:
page.rotateClockwise(180)
pdf_writer.addPage(page)
path = os.path.join(sys.argv[1], '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