def text_string(string: bytes) -> str:
    """Transform a fundamental string into a text string."""
    if string is None: return None
    res = ''
    string = unescape_literal_string(string)
    if string[0:1] == b'(': # Literal string
        if string[1:3] == b'\xfe\xff': 
            res = string[3:-1].decode('utf-16be')
        else:
            s = string[1:-1]
            # = s.replace(b'\x5c\x5c', b'\x5c') # x5c is backslash
            # = s.replace(b'\x5c(', b'(')
            # = s.replace(b'\x5c)', b')')
            res = decode_pdfdoc(s)
    elif string[0:1] == b'<': # Hexadecimal string
        if string[1:5] == b'FEFF':
            b = bytes.fromhex(string[5:-1].decode('ascii'))
            res = b.decode('utf-16be')
        else:
            b = bytes.fromhex(decode_pdfdoc(string[1:-1]))
            res = decode_pdfdoc(b)
    return res
Transform a fundamental string into a text string.
pdfsyntax/text.py