function parseTextStream(textStream) {
  const decodedStream = textStream.toString('utf8');

  // Extract font and font size
  const fontMatch = decodedStream.match(/\/([A-Za-z0-9]+)\s+(\d+)\s+Tf/);

  if (!fontMatch) {
    return undefined;
  }

  const font = fontMatch[1];
  const fontSize = parseInt(fontMatch[2], 10);

  // Extract hex strings inside TJ array
  const tjMatch = decodedStream.match(/\[([^\]]+)\]\s+TJ/);
  if (!tjMatch) {
    return undefined;
  }
  let text = '';

  // this is a simplified version
  // the correct way is to retrieve the encoding from /Resources /Font dictionary and decode using it
  // https://stackoverflow.com/a/29468049/5724645

  // Match all hex strings like <...>
  const hexMatches = [...tjMatch[1].matchAll(/<([0-9a-fA-F]+)>/g)];
  for (const m of hexMatches) {
    // Convert hex to string
    const hex = m[1];
    for (let i = 0; i < hex.length; i += 2) {
      const code = parseInt(hex.substr(i, 2), 16);
      let char = String.fromCharCode(code);
      // Handle special cases
      if (code === 0x0a) {
        char = '\n'; // Newline
      } else if (code === 0x0d) {
        char = '\r'; // Carriage return
      } else if (code === 0x85) {
        char = '...';
      }
      text += char;
    }
  }

  return { text, font, fontSize };
}
@param {Buffer} textStream
@return {TextStream | undefined}