PDFReader 2.5.1

PDFReader 2.5.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年11月
SwiftSwift版本4.0
SPM支持SPM

Ricardo Nunez 维护。



PDFReader 2.5.1

  • Alua Kinzhebayeva

iOS-PDF-Reader

用Swift编写的iOS PDF阅读器

  • 快速且轻量级
  • 底部有缩略图栏,可以导航到特定页面
  • 右上角的打印按钮

Example

Example

要求

  • iOS 8.0+

用法

创建一个PDFDocument

从文件URL
let documentFileURL = Bundle.main.url(forResource: "Cupcakes", withExtension: "pdf")!
let document = PDFDocument(url: documentFileURL)!
从远程URL
let remotePDFDocumentURLPath = "http://devstreaming.apple.com/videos/wwdc/2016/201h1g4asm31ti2l9n1/201/201_internationalization_best_practices.pdf"
let remotePDFDocumentURL = URL(string: remotePDFDocumentURLPath)!
let document = PDFDocument(url: documentRemoteURL)!
从数据
let document = PDFDocument(fileData: fileData, fileName: "Sample PDF")!

显示一个PDFDocument

let readerController = PDFViewController.createNew(with: document)
navigationController?.pushViewController(readerController, animated: true)

自定义

控制器标题

PDFViewController.createNew(with: document, title: "Favorite Cupcakes")

背景颜色

controller.backgroundColor = .white

操作按钮图像和动作

可用的操作样式
/// Action button style
public enum ActionStyle {
    /// Brings up a print modal allowing user to print current PDF
    case print

    /// Brings up an activity sheet to share or open PDF in another app
    case activitySheet

    /// Performs a custom action
    case customAction((Void) -> ())
}
let actionButtonImage = UIImage(named: "cupcakeActionButtonImage")
PDFViewController.createNew(with: document, title: "Favorite Cupcakes", actionButtonImage: actionButtonImage, actionStyle: .activitySheet)

重写默认的返回按钮

/// Create a button to override the default behavior of the backbutton.  In the below example we create a cancel button which will call our myCancelFunc method on tap.
let myBackButton = UIBarButtonItem(title: "Cancel", style: .done, target: self, action:  #selector(self.myCancelFunc(_:)))
/// Provide your button to createNew using the backButton parameter.  The PDFViewController will then use your button instead of the default backbutton.
PDFViewController.createNew(with: document, title: "Favorite Cupcakes", backButton: myBackButton)

不要在控制器中加载缩略图

let controller = PDFViewController.createNew(with: document, isThumbnailsEnabled: false)

从左到右改为从上到下更改页面的滚动方向

controller.scrollDirection = .vertical

鸣谢

灵感来源于PDF阅读器 https://github.com/vfr/Reader 和苹果的TiledScrollView示例。