code: def generate_pdf(
      *,
      input_file: Path,
      output_pdf: Path,
      output_text: Path,
      languages: list[str],
      engine_mode: int,
      tessconfig: list[str],
      timeout: float,
      pagesegmode: int,
      thresholding: int,
      user_words,
      user_patterns,
  ) -> None:
      """Generate a PDF using Tesseract's internal PDF generator.
  
      We specifically a text-only PDF which is more suitable for combining with
      the input page.
      """
      args_tesseract = tess_base_args(languages, engine_mode)
  
      if pagesegmode is not None:
          args_tesseract.extend(["--psm", str(pagesegmode)])
  
      args_tesseract.extend(["-c", "textonly_pdf=1"])
  
      if thresholding != 0 and has_thresholding():
          args_tesseract.extend(
              ["-c", f"thresholding_method={thresholding}"]
          )
  
      if user_words:
          args_tesseract.extend(["--user-words", user_words])
  
      if user_patterns:
          args_tesseract.extend(["--user-patterns", user_patterns])
  
      prefix = output_pdf.parent / Path(output_pdf.stem)
  
      # Reminder: test suite tesseract test plugins might break after any changes
      # to the number of order parameters here
  
      args_tesseract.extend(
          [fspath(input_file), fspath(prefix), "pdf", "txt"]
      )
      args_tesseract.extend(tessconfig)
      try:
          p = run(
              args_tesseract,
              stdout=PIPE,
              stderr=STDOUT,
              timeout=timeout,
              check=True,
          )
          stdout = p.stdout
          with suppress(FileNotFoundError):
              prefix.with_suffix(".txt").replace(output_text)
      except TimeoutExpired:
          page_timedout(timeout)
          use_skip_page(output_pdf, output_text)
      except CalledProcessError as e:
          tesseract_log_output(e.output)
          if (
              b"Image too large" in e.output
              or b"Empty page!!" in e.output
          ):
              use_skip_page(output_pdf, output_text)
              return
          raise SubprocessOutputError() from e
      else:
          tesseract_log_output(stdout)
  
imports: from __future__ import annotations
  import logging
  import re
  from contextlib import suppress
  from math import pi
  from os import fspath
  from pathlib import Path
  from subprocess import PIPE, STDOUT, CalledProcessError, TimeoutExpired
  from packaging.version import Version
  from ocrmypdf.exceptions import MissingDependencyError, SubprocessOutputError, TesseractConfigError
  from ocrmypdf.pluginspec import OrientationConfidence
  from ocrmypdf.subprocess import get_version, run
label_desc: Use image node_id 13 for calling a global function with example usage: generate_pdf() without return types