Как открыть PDF в приложении какао - PullRequest
3 голосов
/ 16 марта 2012

Я хотел бы открыть PDF-файл в приложении Какао. Я попробовал следующее, чтобы открыть PDF с помощью Preview.

[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:@"filepath"]];

Но я хотел бы открыть прикрепленный к окну PDF-файл, аналогичный окну справки Xcode. Как этого добиться с помощью PDFKit?

Ответы [ 3 ]

5 голосов
/ 31 марта 2012

Я импортировал QuartzFrameWork и добавил PDFView в xib.Следующий код сделал эту работу за меня:

NSURL *url = [NSURL fileURLWithPath:@"filePath"]
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:url];
[_pdfView setDocument:pdfDoc];
4 голосов
/ 16 марта 2012

Вы можете использовать PDFView для открытия файлов PDF в вашем приложении.

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/PDFKitGuide/PDFKit_Prog_Intro/PDFKit_Prog_Intro.html#//apple_ref/doc/uid/TP40001863-CH203-SW1

0 голосов
/ 29 ноября 2018

в .h файле

@interface MyViewController:UIViewController <UIDocumentInteractionControllerDelegate>
@property(nonatomic, retain) UIDocumentInteractionController *documentInteractionController;

в .m файле

@synthesize documentInteractionController;
- (void)viewDidLoad{
[super viewDidLoad];
documentInteractionController = [[UIDocumentInteractionController alloc] init];
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
return self;
}
-(void) openPdf{
NSString *filePath=filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"filename" ofType:@"pdf"];
NSURL *URL = [NSURL fileURLWithPath:filePath];
if (URL) {
    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
    [self.documentInteractionController setDelegate:self];
    [self.documentInteractionController presentPreviewAnimated:YES];
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...