【问题标题】:How to use PDFView in cocoa app?如何在可可应用程序中使用 PDFView?
【发布时间】:2011-12-20 04:19:08
【问题描述】:

我现在正在研究可可,对 mac 开发有点陌生。
我想从我的服务器打开 PDF。 PDFView 可以做到这一点吗?
如果有人在这方面指导我,那将对我非常有帮助。
是否有任何示例代码可以在 PDFView 中打开 PDF 文件?

提前谢谢..!!!

【问题讨论】:

    标签: macos cocoa xcode4 pdfview


    【解决方案1】:

    Swift 3.0 版本:)

        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
    

    【讨论】:

      【解决方案2】:

      Swift 版本(别忘了导入 Quartz 模块)

          guard let docPath = NSBundle.mainBundle().pathForResource("1", ofType: "pdf") else { return }
      
          let docURL = NSURL.fileURLWithPath(docPath)
          let pdfDocument = PDFDocument(URL: docURL)
      

      【讨论】:

        【解决方案3】:

        我得到了答案..

        至少为我工作.. :)

        NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"1.pdf" ofType:nil];
        NSURL *url = [NSURL fileURLWithPath:urlStr];
        PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:url];
        [pdfView setDocument:pdfDoc];
        

        【讨论】:

          猜你喜欢
          • 2019-01-14
          • 1970-01-01
          • 1970-01-01
          • 2016-07-11
          • 2016-08-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-15
          相关资源
          最近更新 更多