def pdf_remove(source: str, pages: [str], output: str = None):
if output is not None and os.path.isfile(output):<EOL><INDENT>if overwrite_dlg(output) is False:<EOL><INDENT>return<EOL><DEDENT><DEDENT>writer = PdfFileWriter()<EOL>srcfile = open(source, "<STR_LIT:rb>")<EOL>srcreader = PdfFileReader(srcfile)<EOL>pages = parse_rangearg(pages, len(srcreader.pages))<EOL>for pagenr, page in enumerate(srcreader.pages):<EOL><INDENT>if pagenr not in pages:<EOL><INDENT>writer.addPage(page)<EOL><DEDENT><DEDENT>if output is None:<EOL><INDENT>outfile = NamedTemporaryFile(delete=False)<EOL><DEDENT>else:<EOL><INDENT>outfile = open(output, "<STR_LIT:wb>")<EOL><DEDENT>writer.write(outfile)<EOL>srcfile.close()<EOL>outfile.close()<EOL>if output is None:<EOL><INDENT>if overwrite_dlg(source):<EOL><INDENT>os.remove(source)<EOL>move(outfile.name, source)<EOL><DEDENT>else:<EOL><INDENT>os.remove(outfile)<EOL><DEDENT><DEDENT>
Remove pages from a PDF source file.
:param source: pdf source file
:param pages: list of page numbers or range expressions
:param output: pdf output file