SimplePDFViewer 0.1.1

SimplePDFViewer 0.1.1

Maintained by Frank Jia.



  • By
  • Frank Jia

SimplePDFViewer

An easy to use UIViewController that renders local & remote PDF's with basic customization and functionality.

Version License Platform

Introduction

SimplePDFViewer lets you show PDF documents when very little customization/advanced functionality is required. The library is built on top of Apple's PDFKit.

Standard VC Error VC Dialog

Features include:

  • Initialization from local/remote URL, raw data, or PDFDocument
  • Jump-to-page dialog
  • Page tracking
  • Export file using standard iOS sharesheet
  • Basic customization (tint, error message, VC title, etc.)

The library was created to provide basic PDF functionality for another application. It will be maintained by myself, Frank Jia. If there is demand, I'm open to adding functionality and additional customization. Don't hesistate to reach out at [email protected].

Usage

SimplePDFViewer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SimplePDFViewer'

To use SimplePDFViewer, import SimplePDFViewer. You can then instantiate an instance of the VC like so:

let pdfVC = SimplePDFViewController(urlString: ViewController.TEST_PDF_URL)
pdfVC.viewTitle = "Test View Title" // Custom view title on top bar
pdfVC.tint = .red // Tint applies to all views in the VC
pdfVC.exportPDFName = "TestExportPDF" // File name for sharing, default is "Document"
pdfVC.errorMessage = "Uh oh!" // Custom error message if PDF fails to load
pdfVC.dismissalDelegate = self // Customize what happens when close button is pressed

There are also constructors for the VC from a URL, PDFDocument, or raw Data. You can then present the VC using:

present(pdfVC, animated: true, completion: nil) // Presents modally
navigationController?.pushViewController(pdfVC, animated: true) // Pushes onto navigation stack

Delegates

There is currently one delegate: SimplePDFViewOnDismissDelegate Here's an example implementation:

func didDismiss(_ sender: SimplePDFViewController) {
// It is your responsibility to dismiss the VC
sender.dismiss(animated: true, completion: nil)
// Do whatever else you want to do
print("Hello!")
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

License

SimplePDFViewer is available under the MIT license. See the LICENSE file for more info.