code: def pdf_remove(source: str, pages: [str], output: str = None):
      
      if output is not None and os.path.isfile(output):
          if overwrite_dlg(output) is False:
              return
  
      writer = PdfFileWriter()
      srcfile = open(source, "rb")
      srcreader = PdfFileReader(srcfile)
  
      # Add pages, leave out removed pages
      pages = parse_rangearg(pages, len(srcreader.pages))
      for pagenr, page in enumerate(srcreader.pages):
          if pagenr not in pages:
              writer.addPage(page)
  
      # Open output file or temporary file for writing
      if output is None:
          outfile = NamedTemporaryFile(delete=False)
      else:
          outfile = open(output, "wb")
  
      # Write file and close
      writer.write(outfile)
      srcfile.close()
      outfile.close()
  
      # Move temporary file to source
      if output is None:
          if overwrite_dlg(source):
              os.remove(source)
              move(outfile.name, source)
          else:
              os.remove(outfile)
docs: 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