Open a local file on iOS

Nutrient iOS SDK enables you to open PDF and image (PNG, JPEG, and TIFF) files from your device’s local storage. This article shows how to open a PDF document from local storage.

First, you need to add the PDF document you want to display to your application by dragging it into your project. On the dialog that’s displayed, select Finish to accept the default integration options. You can use this welcome PDF(opens in a new tab) as an example.

drag and drop document

Then, load your PDF document and display the view controller. This can be done in a button action handler, table view cell selection delegate, or similar:

// Update to use your document name.
let fileURL = Bundle.main.url(forResource: "Document", withExtension: "pdf")!
let document = Document(url: fileURL)
// The configuration closure is optional and allows additional customization.
let pdfController = PDFViewController(document: document) {
$0.isPageLabelEnabled = false
}
// Present the PDF view controller within a `UINavigationController` to show built-in toolbar buttons.
present(UINavigationController(rootViewController: pdfController), animated: true)

For more details about opening a document from local storage, refer to PlaygroundExample.swift(opens in a new tab) in the Nutrient Catalog(opens in a new tab) app.

Using the document browser

Nutrient also allows you to open a document using the system document browser. For more details and a runnable sample project, take a look at the SwiftUI document browser example project on GitHub(opens in a new tab).