показать загруженный PDF с CGPDFDocumentRef - PullRequest
3 голосов
/ 28 декабря 2010

У меня проблема, и я надеюсь, что кто-то может мне помочь.

Я загружаю PDF-файл в DocumentDirectory

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, TRUE);
NSString *documentsDirectory = [paths objectAtIndex:0];
studioPath = [[documentsDirectory stringByAppendingPathComponent:@"test.pdf"] retain];
ASIHTTPRequest *request = [[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://testURL.com/test.pdf"]] retain];
[request setDownloadDestinationPath:studioPath];

, это не весь код, но я надеюсь, вы понимаете, чтоЯ имею в виду.

После этого я покажу этот PDF

CGPDFDocumentRef pdf;
CFStringRef fullPathEscaped = CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)studioPath, NULL, NULL,kCFStringEncodingUTF8);

CFURLRef docUrl = CFURLCreateWithFileSystemPath (NULL, fullPathEscaped, kCFURLPOSIXPathStyle, FALSE);  
pdf = CGPDFDocumentCreateWithURL(docUrl);

, но он всегда вылетает, когда я использую интернет-URL вместо studioPath к PDF, он работает, но я бы не стал скачиватьPDF более одного раза.

1 Ответ

2 голосов
/ 12 марта 2012

Попробуйте это

 CFURLRef pdfURL = (CFURLRef)[[NSURL alloc] initFileURLWithPath:[documentsDirectory stringByAppendingPathComponent:source]];
    //file ref
    CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...