Pregunta

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..!!!

¿Fue útil?

Solución

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

Otros consejos

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)

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top