code: def gettext(args):
      doc = open_file(args.input, args.password, pdf=False)
      pagel = get_list(args.pages, doc.page_count + 1)
      output = args.output
      if output == None:
          filename, _ = os.path.splitext(doc.name)
          output = filename + ".txt"
      textout = open(output, "wb")
      flags = TEXT_PRESERVE_LIGATURES | TEXT_PRESERVE_WHITESPACE
      if args.convert_white:
          flags ^= TEXT_PRESERVE_WHITESPACE
      if args.noligatures:
          flags ^= TEXT_PRESERVE_LIGATURES
      if args.extra_spaces:
          flags ^= TEXT_INHIBIT_SPACES
      func = {
          "simple": page_simple,
          "blocks": page_blocksort,
          "layout": page_layout,
      }
      for pno in pagel:
          page = doc[pno - 1]
          func[args.mode](
              page,
              textout,
              args.grid,
              args.fontsize,
              args.noformfeed,
              args.skip_empty,
              flags=flags,
          )
  
      textout.close()
  
imports: import argparse
  import bisect
  import os
  import sys
  import statistics
  from typing import Dict, List, Set, Tuple
  import fitz
  from fitz.fitz import TEXT_INHIBIT_SPACES, TEXT_PRESERVE_LIGATURES, TEXT_PRESERVE_WHITESPACE
label_desc: Use image node_id 19 for calling a global function with example usage: gettext(args) without return types