PSPDFKit for iOS is a framework dealing with everything related to PDF. It’s a large library which exposes a lot of API so that many aspects can be customized. The API can be intimidating at first, so in this article, we will walk you through the basics, covering how to download PSPDFKit for iOS and use the bundled sample projects. We will also integrate PSPDFKit and present a
PSPDFViewController in an existing app.
The first step to getting started with PSPDFKit is to download the
dmg file, which contains the framework and a few Xcode projects for the sample apps. If you don’t already have PSPDFKit, sign up to download our 60-day trial. Afterward, you will receive an email with the download link.
Launch the Sample App in Xcode
Now that you’ve downloaded PSPDFKit on your Mac, open the
.dmg file and navigate to the
Make sure you have the latest stable version of Xcode installed on your Mac and open the
Launch the project in Simulator to see PSPDFKit in action. The
PSPDFCatalog project comes with a lot of examples, and a good starting point is the “PSPDFViewController Playground” example, which illustrates how to open a PDF document in a
We encourage you to explore the catalog app and its examples. You can use the search bar in the catalog app or search the Xcode project for use cases which may fit your app’s needs.
Integrate PSPDFKit in Your Own App
Now that we’ve covered the basics, we will proceed to integrate the framework into an existing app using CocoaPods. There are several ways to integrate PSPDFKit; see our “Integrating PSPDFKit” guide article for all the integration methods.
In this tutorial, we will be using CocoaPods because it is the simplest and most popular way to add dependencies to a project. We are assuming that your project is already using CocoaPods and that it already has a
Podfile. Please modify it as such and run
1 2 3 4 5 6
use_frameworks! target :YourTargetName do # Other Pods pod ’PSPDFKit', podspec: 'https://customers.pspdfkit.com/cocoapods/YOUR_COCOAPODS_KEY_GOES_HERE/latest.podspec' end
You can find your demo CocoaPods key prefilled on our “Try the PSPDFKit Demo” article.
If you already have a license, please enter it in your application delegate’s
willFinishLaunchingWithOptions. See our “Adding the License Key” guide for the step-by-step instructions. Otherwise, if you are using the trial version, you can skip this step for now.
Present the PSPDFViewController
Your project is now using PSPDFKit via CocoaPods. You need to add the imports for
PSPDFKitUI and present a
PSPDFViewController from within your app:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Import PSPDFKit and PSPDFKitUI import PSPDFKit import PSPDFKitUI ... // Create the PSPDFDocument. let documentURL = ... let document = PSPDFDocument(url: writableURL) // Create the PDF view controller. let pdfController = PSPDFViewController(document: document, configuration: configuration) // Present the PDF view controller within a UINavigationController to enable the toolbar. present(UINavigationController(rootViewController: pdfController), animated: true)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Import PSPDFKit and PSPDFKitUI @import PSPDFKit; @import PSPDFKitUI; ... // Create the PSPDFDocument. // This is the container for your PDF file. It can also manage multiple files. NSURL *documentURL = ... PSPDFDocument *document = [[PSPDFDocument alloc] initWithURL:documentURL]; // Create the PDF view controller. PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document]; // Present the PDF view controller within a UINavigationController to enable the toolbar. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pdfController]; [self presentViewController:navController animated:YES completion:NULL];
PSPDFKit for iOS has a vast API that allows you to fully customize things like the appearance, the annotation toolbar, and so much more. As a next step, we recommend that you consult the API and our documentation guides. Feel free to reach out if you have any questions or concerns. We’re here to help!