code: def generate_pdfa(
      pdf_pages,
      output_file: os.PathLike,
      *,
      compression: str,
      color_conversion_strategy: str,
      pdf_version: str = "1.5",
      pdfa_part: str = "2",
      progressbar_class=None,
      stop_on_error: bool = False,
  ):
      # Ghostscript's compression is all or nothing. We can either force all images
      # to JPEG, force all to Flate/PNG, or let it decide how to encode the images.
      # In most case it's best to let it decide.
      compression_args = []
      if compression == "jpeg":
          compression_args = [
              "-dAutoFilterColorImages=false",
              "-dColorImageFilter=/DCTEncode",
              "-dAutoFilterGrayImages=false",
              "-dGrayImageFilter=/DCTEncode",
          ]
      elif compression == "lossless":
          compression_args = [
              "-dAutoFilterColorImages=false",
              "-dColorImageFilter=/FlateEncode",
              "-dAutoFilterGrayImages=false",
              "-dGrayImageFilter=/FlateEncode",
          ]
      else:
          compression_args = [
              "-dAutoFilterColorImages=true",
              "-dAutoFilterGrayImages=true",
          ]
  
      gs_version = version()
      if gs_version == Version("9.56.0"):
          # 9.56.0 breaks our OCR, should be fixed in 9.56.1
          # https://bugs.ghostscript.com/show_bug.cgi?id=705187
          compression_args.append("-dNEWPDF=false")
  
      if os.name == "nt":
          # Windows has lots of fatal "permission denied" errors
          stop_on_error = False
  
      # nb no need to specify ProcessColorModel when ColorConversionStrategy
      # is set; see:
      # https://bugs.ghostscript.com/show_bug.cgi?id=699392
      args_gs = (
          [
              GS,
              "-dBATCH",
              "-dNOPAUSE",
              "-dSAFER",
              f"-dCompatibilityLevel={str(pdf_version)}",
              "-sDEVICE=pdfwrite",
              "-dAutoRotatePages=/None",
              f"-sColorConversionStrategy={color_conversion_strategy}",
          ]
          + (["-dPDFSTOPONERROR"] if stop_on_error else [])
          + compression_args
          + [
              "-dJPEGQ=95",
              f"-dPDFA={pdfa_part}",
              "-dPDFACompatibilityPolicy=1",
              "-o",
              "-",
              "-sstdout=%stderr",  # Literal %s, not string interpolation
          ]
      )
      args_gs.extend(
          fspath(s) for s in pdf_pages
      )  # Stringify Path objs
      try:
          with Path(output_file).open("wb") as output:
              p = run_polling_stderr(
                  args_gs,
                  stdout=output,
                  stderr=PIPE,
                  check=True,
                  text=True,
                  encoding="utf-8",
                  errors="replace",
                  callback=GhostscriptFollower(progressbar_class),
              )
      except CalledProcessError as e:
          # Ghostscript does not change return code when it fails to create
          # PDF/A - check PDF/A status elsewhere
          log.error(e.stderr)
          raise SubprocessOutputError(
              "Ghostscript PDF/A rendering failed"
          ) from e
      else:
          stderr = p.stderr
          # If there is an error we log the whole stderr, except for filtering
          # duplicates.
          if _gs_error_reported(stderr):
              # Ghostscript outputs the pattern **** Error: ....  frequently.
              # Occasionally the error message is spammed many times. We filter
              # out duplicates of this message using the filter above. We use
              # the **** pattern to split the stderr into parts.
              for part in stderr.split("****"):
                  log.error(part)
          if _gs_devicen_reported(stderr):
              raise ColorConversionNeededError()
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  from collections import deque
  from io import BytesIO
  from os import fspath
  from pathlib import Path
  from subprocess import PIPE, CalledProcessError
  from packaging.version import Version
  from PIL import Image, UnidentifiedImageError
  from ocrmypdf.exceptions import ColorConversionNeededError, SubprocessOutputError
  from ocrmypdf.helpers import Resolution
  from ocrmypdf.subprocess import get_version, run, run_polling_stderr
label_desc: Use image node_id 5 for calling a global function with example usage: generate_pdfa(pdf_pages, output_file) without return types