Reputation: 1075
I am working on cocoa now a days so, little bit new to mac development.
I want to open a PDF from my server. Is this possible with PDFView
?
If anyone guide me in this then it will be very helpful for me.
Is there any sample code to open a PDF file in PDFView ?
Thanks in advance..!!!
Upvotes: 1
Views: 3227
Reputation: 1044
Swift 3.0 version:)
guard let docPath = Bundle.main.path(forResource: "1", ofType: "pdf") else { return }
let docURL = NSURL.fileURL(withPath: docPath)
let pdfDocument = PDFDocument(url: docURL)
uxPdf.document = pdfDocument
Upvotes: 1
Reputation:
Swift version (do not forget to import Quartz module)
guard let docPath = NSBundle.mainBundle().pathForResource("1", ofType: "pdf") else { return }
let docURL = NSURL.fileURLWithPath(docPath)
let pdfDocument = PDFDocument(URL: docURL)
Upvotes: 3
Reputation: 1075
I got answer..
at least working for me.. :)
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"1.pdf" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:url];
[pdfView setDocument:pdfDoc];
Upvotes: 4