def pdf_split(<EOL>input: str, output: str, stepsize: int = <NUM_LIT:1>, sequence: [int] = None<EOL>):
output = output or os.path.splitext(input)[<NUM_LIT:0>]<EOL>if not os.path.isfile(input):<EOL><INDENT>print("<STR_LIT>" % input)<EOL>return<EOL><DEDENT>with open(input, "<STR_LIT:rb>") as inputfile:<EOL><INDENT>reader = PdfFileReader(inputfile)<EOL>pagenr = <NUM_LIT:0><EOL>outputfile = None<EOL>if sequence is None:<EOL><INDENT>for i, page in enumerate(reader.pages):<EOL><INDENT>if not i % stepsize:<EOL><INDENT>pagenr += <NUM_LIT:1><EOL>outputfile = open(output + "<STR_LIT>" % pagenr, "<STR_LIT:wb>")<EOL>writer = PdfFileWriter()<EOL><DEDENT>writer.addPage(page)<EOL>if not (i + <NUM_LIT:1>) % stepsize:<EOL><INDENT>writer.write(outputfile)<EOL>outputfile.close()<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>sequence = map(int, sequence)<EOL>iter_pages = iter(reader.pages)<EOL>for filenr, pagecount in enumerate(sequence):<EOL><INDENT>with open(<EOL>output + "<STR_LIT>" % (filenr + <NUM_LIT:1>), "<STR_LIT:wb>"<EOL>) as outputfile:<EOL><INDENT>writer = PdfFileWriter()<EOL>for i in range(pagecount):<EOL><INDENT>try:<EOL><INDENT>page = next(iter_pages)<EOL>writer.addPage(page)<EOL><DEDENT>except StopIteration:<EOL><INDENT>writer.write(outputfile)<EOL>return<EOL><DEDENT><DEDENT>writer.write(outputfile)<EOL><DEDENT><DEDENT><DEDENT>if not outputfile.closed:<EOL><INDENT>writer.write(outputfile)<EOL>outputfile.close()<EOL><DEDENT><DEDENT>
Split the input file in multiple output files
:param input: name of the input file
:param output: name of the output files
:param stepsize: how many pages per file, only if sequence is None
:param sequence: list with number of pages per file