How to open a PDF file in the Cocoa app

I would like to open a PDF file in a Cocoa application. I tried the following to open the PDF using Preview.

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


But I would like to open a PDF attached to a window similar to the Xcode help window. How do you achieve this with PDFKit?


source to share

2 answers



I imported QuartzFrameWork and added PDFView

to xib. The following code did the job for me:

NSURL *url = [NSURL fileURLWithPath:@"filePath"]
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:url];
[_pdfView setDocument:pdfDoc];




All Articles