iosobjective-ccgpdfdictionaryrefcgpdfscanner

Reading exact text from the "Tj/TJ" operator of CGPDFDictionaryRef


I am trying to read text from the "Tj/TJ" operator of CGPDFDictionary, but the TJ/Tj operator has the text in (encoded) format for e.g, Tj = <00><1F><05>. Now i want to get this exact text in NSString i.e NSString should contain "<00><1F><05>".I tried to get the content from TJ/Tj in CGPDFStringRef, but when i am trying to put it in const unsigned char* using CGPDFStringGetBytePtr or in NSString using CGPDFStringCopyTextString i am not getting the desired output. Please suggest me a solution.


Solution

  • Got the answer:

    size_t length = CGPDFStringGetLength(string);
    NSData *oprData = [NSData dataWithBytes:CGPDFStringGetBytePtr(string) length:length];
    NSString *hexString = [[NSString stringWithFormat:@"%@",oprData] uppercaseString];
    

    Here string is the CGPDFStringRef. Finally we get the content of Tj/TJ operator in hexString variable.