code: def convert_to_jbig2(pike, jbig2_groups, root, log, options):
      
  
      _produce_jbig2_images(jbig2_groups, root, log, options)
  
      for group, xref_exts in jbig2_groups.items():
          prefix = f'group{group:08d}'
          jbig2_symfile = root / (prefix + '.sym')
          if jbig2_symfile.exists():
              jbig2_globals_data = jbig2_symfile.read_bytes()
              jbig2_globals = pikepdf.Stream(pike, jbig2_globals_data)
              jbig2_globals_dict = Dictionary(JBIG2Globals=jbig2_globals)
          elif options.jbig2_page_group_size == 1:
              jbig2_globals_dict = None
          else:
              raise FileNotFoundError(jbig2_symfile)
  
          for n, xref_ext in enumerate(xref_exts):
              xref, _ = xref_ext
              jbig2_im_file = root / (prefix + f'.{n:04d}')
              jbig2_im_data = jbig2_im_file.read_bytes()
              im_obj = pike.get_object(xref, 0)
              im_obj.write(
                  jbig2_im_data, filter=Name.JBIG2Decode, decode_parms=jbig2_globals_dict
              )
docs: Convert images to JBIG2 and insert into PDF.
  
      When the JBIG2 page group size is > 1 we do several JBIG2 images at once
      and build a symbol dictionary that will span several pages. Each JBIG2
      image must reference to its symbol dictionary. If too many pages shared the
      same dictionary JBIG2 encoding becomes more expensive and less efficient.
      The default value of 10 was determined through testing. Currently this
      must be lossy encoding since jbig2enc does not support refinement coding.
  
      When the JBIG2 symbolic coder is not used, each JBIG2 stands on its own
      and needs no dictionary. Currently this must be lossless JBIG2.