-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
There is currently the following script but it would be nice to integrate this into the software
from PyPDF2 import PdfFileReader, PdfFileWriter
import sys
import subprocess
import re
from shlex import quote
reg = re.compile(r'(?:Gruppe:\s*)(\d*)')
inputfilename = sys.argv[1]
inputfilename_safe = quote(inputfilename)
input = PdfFileReader(open(inputfilename, 'rb'))
pages = input.getNumPages()
gruppe = 1
output = PdfFileWriter()
outfilename_prefix = inputfilename.split('.pdf',1)[0]
# We do not know the group number yet so we do a dumy replace
outfilename = '{}-Gruppe-{}.pdf'.format(outfilename_prefix, '{}')
for i in range(1, pages + 1):
ret = subprocess.getoutput('pdftotext -f {0} -l {0} {1} -'.format(i, inputfilename_safe))
if 'für Frage' in ret and i != 1:
outfile = open(outfilename.format(gruppe), 'wb')
output.write(outfile)
outfile.close()
output = PdfFileWriter()
gruppe = int(reg.search(ret).group(1))
output.addPage(input.getPage(i - 1))
outfile = open(outfilename.format(gruppe), 'wb')
gruppe += 1
output.write(outfile)
outfile.close()