code: def is_ocr_required(page_context: PageContext) -> bool:
      """Check if the page needs to be OCR'd."""
      pageinfo = page_context.pageinfo
      options = page_context.options
  
      ocr_required = True
  
      if options.pages and pageinfo.pageno not in options.pages:
          log.debug(
              f"skipped {pageinfo.pageno} as requested by --pages {options.pages}"
          )
          ocr_required = False
      elif pageinfo.has_text:
          if not options.force_ocr and not (
              options.skip_text or options.redo_ocr
          ):
              raise PriorOcrFoundError(
                  "page already has text! - aborting (use --force-ocr to force OCR; "
                  " see also help for the arguments --skip-text and --redo-ocr"
              )
          elif options.force_ocr:
              log.info(
                  "page already has text! - rasterizing text and running OCR anyway"
              )
              ocr_required = True
          elif options.redo_ocr:
              if pageinfo.has_corrupt_text:
                  log.warning(
                      "some text on this page cannot be mapped to characters: "
                      "consider using --force-ocr instead"
                  )
              else:
                  log.info("redoing OCR")
              ocr_required = True
          elif options.skip_text:
              log.info("skipping all processing on this page")
              ocr_required = False
      elif not pageinfo.images and not options.lossless_reconstruction:
          # We found a page with no images and no text. That means it may
          # have vector art that the user wants to OCR. If we determined
          # lossless reconstruction is not possible then we have to rasterize
          # the image. So if OCR is being forced, take that to mean YES, go
          # ahead and rasterize. If not forced, then pretend there's no text
          # on the page at all so we don't lose anything.
          # This could be made smarter by explicitly searching for vector art.
          if options.force_ocr and options.oversample:
              # The user really wants to reprocess this file
              log.info(
                  "page has no images - "
                  f"rasterizing at {options.oversample} DPI because "
                  "--force-ocr --oversample was specified"
              )
          elif options.force_ocr:
              # Warn the user they might not want to do this
              log.warning(
                  "page has no images - "
                  "all vector content will be "
                  f"rasterized at {VECTOR_PAGE_DPI} DPI, losing some resolution and "
                  "likely increasing file size. Use --oversample to adjust the "
                  "DPI."
              )
          else:
              log.info(
                  "page has no images - "
                  "skipping all processing on this page to avoid losing detail. "
                  "Use --force-ocr if you wish to perform OCR on pages that "
                  "have vector content."
              )
              ocr_required = False
  
      if ocr_required and options.skip_big and pageinfo.images:
          pixel_count = pageinfo.width_pixels * pageinfo.height_pixels
          if pixel_count > (options.skip_big * 1_000_000):
              ocr_required = False
              log.warning(
                  "page too big, skipping OCR "
                  f"({(pixel_count / 1_000_000):.1f} MPixels > "
                  f"{options.skip_big:.1f} MPixels --skip-big)"
              )
      return ocr_required
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import sys
  from collections.abc import Iterable, Iterator, Sequence
  from contextlib import suppress
  from pathlib import Path
  from shutil import copyfileobj, copystat
  from typing import Any, BinaryIO, TypeVar, cast
  import img2pdf
  import pikepdf
  from PIL import Image, ImageColor, ImageDraw
  from ocrmypdf._concurrent import Executor
  from ocrmypdf._exec import unpaper
  from ocrmypdf._jobcontext import PageContext, PdfContext
  from ocrmypdf._metadata import repair_docinfo_nuls
  from ocrmypdf.exceptions import DigitalSignatureError, DpiError, EncryptedPdfError, InputFileError, PriorOcrFoundError, TaggedPDFError, UnsupportedImageFormatError
  from ocrmypdf.helpers import IMG2PDF_KWARGS, Resolution, safe_symlink
  from ocrmypdf.hocrtransform import DebugRenderOptions, HocrTransform
  from ocrmypdf.hocrtransform._font import Courier
  from ocrmypdf.pdfa import generate_pdfa_ps
  from ocrmypdf.pdfinfo import Colorspace, Encoding, PageInfo, PdfInfo
  from ocrmypdf.pluginspec import OrientationConfidence
label_desc: Use image node_id 9 for calling a global function with example usage: is_ocr_required(page_context) and returns: ocr_required