2014-09-15 3 views
0

Я пытаюсь получить PDF-файл с помощью NSSearchPathForDirectoriesInDomains.i, я получаю путь для файла PDF, но как преобразовать этот pdf-файл в nsdata или nsmutabledata (байты). Вот мой код, чтобы получить путь к PDF-файлу ,Как получить PDF в iPhone

NSArray *arrayPaths1 = 
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
NSString *path1 = [arrayPaths1 objectAtIndex:0]; 
path1 = [path1 stringByAppendingPathComponent:@"mypdffile.pdf"]; 

в path1 я получаю путь и получить байт данных Я пытаюсь

[decodedData writeToFile:path1 atomically:YES]; 

decodedData является NSMutableData.decodedData является nil.Please помочь me.How я могу решить эту проблему?

+1

Почему вы отжимаете файл, который уже я угадываю в папку с документами? – Retro

ответ

0

Для этой цели вы можете использовать [NSData dataWithContentsOfFile:<#path of your file#>].

В вашем случае это должно быть:

decodedData = [NSData dataWithContentsOfFile: path1]; 

Надеется, что это помогает.

0

Try ниже кода ..

NSData *dataPdf = [NSData dataWithContentsOfURL:pdfOnline.url]; 

    //Get path directory 
    NSArray *arrayPaths1 = 
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
    //Create PDF_Documents directory 
    NSString * documentsDirectory = [arrayPaths1 objectAtIndex:0]; 
    documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"mypdffile.pdf"]; 

    [[NSFileManager defaultManager] documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil]; 

    NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"PDFRefYouPreferred"]; 

    [dataPdf writeToFile:filePath atomically:YES]; 

Надеются, что это будет решить проблему ..!

Смежные вопросы