code: def check_pdf(input_file: Path) -> bool:
      """Check if a PDF complies with the PDF specification.
  
      Checks for proper formatting and proper linearization. Uses pikepdf (which in
      turn, uses QPDF) to perform the checks.
      """
      try:
          pdf = pikepdf.open(input_file)
      except pikepdf.PdfError as e:
          log.error(e)
          return False
      else:
          with pdf:
              messages = pdf.check()
              success = True
              for msg in messages:
                  if "error" in msg.lower():
                      log.error(msg)
                      success = False
                  elif (
                      "/DecodeParms: operation for dictionary attempted on object "
                      "of type null" in msg
                  ):
                      pass  # Ignore/spurious warning
                  else:
                      log.warning(msg)
                      success = False
  
              sio = StringIO()
              linearize_msgs = ""
              try:
                  # If linearization is missing entirely, we do not complain. We do
                  # complain if linearization is present but incorrect.
                  pdf.check_linearization(sio)
              except (RuntimeError, pikepdf.ForeignObjectError):
                  pass
              else:
                  linearize_msgs = sio.getvalue()
                  if linearize_msgs:
                      log.warning(linearize_msgs)
  
              if success and not linearize_msgs:
                  return True
              return False
  
imports: from __future__ import annotations
  import logging
  import multiprocessing
  import os
  import shutil
  import warnings
  from collections.abc import Iterable, Sequence
  from contextlib import suppress
  from decimal import Decimal
  from io import StringIO
  from math import isclose, isfinite
  from pathlib import Path
  from statistics import harmonic_mean
  from typing import Any, Callable, Generic, TypeVar
  import img2pdf
  import pikepdf
label_desc: Use image node_id 8 for calling a global function with example usage: check_pdf(input_file) and returns: False, False, True