美文网首页
iOS端 使用Mupdf实现pdf标注

iOS端 使用Mupdf实现pdf标注

作者: 133sheiya | 来源:发表于2021-03-31 17:43 被阅读0次

    项目中如果需要实现在pdf做标注。大可使用mupdf(开源的)

    • 这个[http://www.mupdf.com]是mupdf的官网。
    • 网上的大多数教程都是教怎么去直接集成和使用mupdf的。
    • 通过俩天的努力 我找到一个很好用的别人在mupdf的基础上进行封装的。省去了我们的很多集成步骤。这里放下他的地址https://github.com/ArtifexSoftware/mupdf-ios-appkit
    • 注意下 不要直接点下载 看截图
      image.png
      使用git clone 下来。 我的之前直接下载 有报错。好像git clone 他还会去下载最新的依赖文件

    最后再看下我项目中如何使用

    1. command + B 获取 真机下的framework 我这里没有做模拟器的framework 需要的自己去合并 .

      image.png
    2. mupdfdk.framework拖入到工程中

      image.png
    3. 配置mupdfdk.framework

      image.png
    4. 测试

    • 把pdf文件写入到document文件夹下。
     let fileManager = FileManager.default
            let docsDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
            let filePath1 = Bundle.main.path(forResource: "iOS_20200804172410", ofType: "pdf") ?? ""
            let filePath2 = Bundle.main.path(forResource: "rk", ofType: "pdf") ?? ""
            if !fileManager.fileExists(atPath: docsDir + "/rk.pdf") {
               try? fileManager.copyItem(atPath: filePath2, toPath: docsDir + "/rk.pdf")
            }
            if !fileManager.fileExists(atPath: docsDir + "/iOS_20200804172410.pdf") {
               try? fileManager.copyItem(atPath: filePath1, toPath: docsDir + "/iOS_20200804172410.pdf")
            }
    
    
    • 跳转到mupdf界面
     @objc func btnClickAction() {
           
            if  let vc = CustomUIDocumentViewController(forPath: "iOS_20200804172410.pdf") {
                self.navigationController?.pushViewController(vc, animated: true)
            }
            
        }
        
        @objc func btnClickAction1() {
           
            if  let vc = CustomUIDocumentViewController(forPath: "rk.pdf") {
                self.navigationController?.pushViewController(vc, animated: true)
            }
            
        }
    

    看效果

    IMG_3729.PNG
    IMG_3730.PNG

    最后 还有很多功能 自己去探索吧!!!!!

    相关文章

      网友评论

          本文标题:iOS端 使用Mupdf实现pdf标注

          本文链接:https://www.haomeiwen.com/subject/lflahltx.html