code: def _generate_ccitt_header(self, data):
          
          # https://stackoverflow.com/questions/2641770/
          # https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf
  
          if not self.decode_parms:
              raise ValueError("/CCITTFaxDecode without /DecodeParms")
  
          if self.decode_parms[0].get("/K", 1) < 0:
              ccitt_group = 4  # Pure two-dimensional encoding (Group 4)
          else:
              ccitt_group = 3
          black_is_one = self.decode_parms[0].get("/BlackIs1", False)
          white_is_zero = 1 if black_is_one else 0
  
          img_size = len(data)
          tiff_header_struct = '<' + '2s' + 'H' + 'L' + 'H' + 'HHLL' * 8 + 'L'
          # fmt: off
          tiff_header = struct.pack(
              tiff_header_struct,
              b'II',  # Byte order indication: Little endian
              42,  # Version number (always 42)
              8,  # Offset to first IFD
              8,  # Number of tags in IFD
              256, 4, 1, self.width,  # ImageWidth, LONG, 1, width
              257, 4, 1, self.height,  # ImageLength, LONG, 1, length
              258, 3, 1, 1,  # BitsPerSample, SHORT, 1, 1
              259, 3, 1, ccitt_group,  # Compression, SHORT, 1, 4 = CCITT Group 4 fax encoding
              262, 3, 1, int(white_is_zero),  # Thresholding, SHORT, 1, 0 = WhiteIsZero
              273, 4, 1, struct.calcsize(tiff_header_struct),  # StripOffsets, LONG, 1, length of header
              278, 4, 1, self.height,
              279, 4, 1, img_size,  # StripByteCounts, LONG, 1, size of image
              0  # last IFD
          )
          # fmt: on
          return tiff_header
docs: Construct a CCITT G3 or G4 header from the PDF metadata