iOS端 使用Mupdf實現pdf標注

項目中如果需要實現在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

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。