code: def convert_to_pdfa(
      input_pdf: Path, input_ps_stub: Path, context: PdfContext
  ) -> Path:
      """Converts the given PDF to PDF/A.
  
      Args:
          input_pdf: The input PDF file path (presumably not PDF/A).
          input_ps_stub: The input PostScript file path, containing instructions
              for the PDF/A generator to use.
          context: The PDF context.
      """
      options = context.options
      input_pdfinfo = context.pdfinfo
      fix_docinfo_file = context.get_path("fix_docinfo.pdf")
      output_file = context.get_path("pdfa.pdf")
  
      # If the DocumentInfo record contains NUL characters, Ghostscript will
      # produce XMP metadata which contains invalid XML entities (&#0;).
      # NULs in DocumentInfo seem to be common since older Acrobats included them.
      # pikepdf can deal with this, but we make the world a better place by
      # stamping them out as soon as possible.
      with pikepdf.open(input_pdf) as pdf_file:
          if repair_docinfo_nuls(pdf_file):
              pdf_file.save(fix_docinfo_file)
          else:
              safe_symlink(input_pdf, fix_docinfo_file)
  
      context.plugin_manager.hook.generate_pdfa(
          pdf_version=input_pdfinfo.min_version,
          pdf_pages=[fix_docinfo_file],
          pdfmark=input_ps_stub,
          output_file=output_file,
          context=context,
          pdfa_part=options.output_type[
              -1
          ],  # is pdfa-1, pdfa-2, or pdfa-3
          progressbar_class=(
              context.plugin_manager.hook.get_progressbar_class()
              if options.progress_bar
              else None
          ),
          stop_on_soft_error=not options.continue_on_soft_render_error,
      )
  
      return output_file
  
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 27 for calling a global function with example usage: convert_to_pdfa(input_pdf, input_ps_stub, context) and returns: output_file