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?

+3


source to share


2 answers


+4


source


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];

      

+4


source







All Articles