tags:

views:

55

answers:

1

I have implementing pdf parsing in which i have parsed pdf and fetch the all text but it disply junks characters so i want to convert in to utf string.How it possible please help me for this question.

A: 

First, you need to find out which encoding is currently used for the text. I guess it's ISO-8859-1, aka Latin-1 or it's variant ISO-8859-15, aka Latin-15.

As soon as know that it's a piece of cake. You haven't said in which container you got the text, e.g. whether it's stored in a C string or NSData.

Let's assume you got a C string. In that case you would do:

myString = [[NSString alloc] initWithBytes:myCString
                                    length:strlen(myCString)
                                  encoding:NSISOLatin1StringEncoding];

If you got a NSData, you would use the initWithData:encoding: initializer instead. That's all you need to do, as according to Apple's documentation, "A string object presents itself as an array of Unicode characters". If you need a UTF8-encoded C string, you can then query it via:

myUTF8CString = [myString UTF8String];

There's also dataUsingEncoding: to get a NSData object instead of a C string.

Have a look at the NSString class reference and the NSStringEncoding constants.

DarkDust