PSPDFKit Ionic is being sunset and will not receive future updates after 1 December 2025. It remains available as source code, should you want to maintain it yourself. All licenses will remain valid and fully supported until 1 December 2025, or until your license expires, whichever occurs later. Interested in transitioning to another Nutrient product? Contact us and we’ll be happy to help.
Requirements
-
The Android NDK
-
An Android Virtual Device or a hardware device
Creating a New Ionic Project
-
In the terminal, change the current working directory to where you’ll save your project. This example uses the
pdf
folder created in the home directory:
mkdir ~/pdf cd ~/pdf
cd /d %userprofile% mkdir pdf cd pdf
-
Create the new Ionic project by running the following command:
ionic start PSPDFKit-Demo blank tabs --cordova --type=angular
Installing the PSPDFKit Ionic Dependency
-
In the terminal, change the location of the current working directory inside the newly created project:
cd PSPDFKit-Demo
-
Add the PSPDFKit plugin:
ionic cordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
-
Open
config.xml
in a text editor to enable AndroidX and to change the deployment target to iOS 15 or later:
open config.xml
Your config.xml
file should look like this:
... <platform name="android"> - <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android"> - <application android:networkSecurityConfig="@xml/network_security_config" /> - </edit-config> + <preference name="AndroidXEnabled" value="true" /> ... </platform> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> + <allow-navigation href="*" /> + <preference name="deployment-target" value="15.0" /> ... </platform> ...
-
Declare
PSPDFKit
in thesrc/declarations.d.ts
file:
echo "declare var PSPDFKit: any;" >> src/declarations.d.ts
Your src/declarations.d.ts
file should look like this:
... declare var PSPDFKit: any;
-
Add the Android platform:
ionic cordova platform add android@latest
-
Open
/platforms/android/app/build.gradle
in a text editor to update the compile SDK version to 31:
open platforms/android/app/build.gradle
Your platforms/android/app/build.gradle
file should look like this:
- compileSdkVersion = cordovaConfig.SDK_VERSION + compileSdkVersion = 31
-
Remove the
cordova-plugin-whitelist
plugin because it was deprecated in template version6.0.0
:
ionic cordova plugin rm cordova-plugin-whitelist
Displaying a PDF
-
Add the PDF document you want to display in your project’s
www
directory. You can use this Quickstart Guide PDF as an example:
cp ~/Downloads/Document.pdf platforms/android/app/src/main/assets/Document.pdf
-
Open the
src/app/app.component.ts
file:
open src/app/app.component.ts
-
Replace the entire contents of the
app.component.ts
file with the following code snippet:
import { Component } from "@angular/core"; import { Platform } from "@ionic/angular"; @Component({ selector: "app-root", templateUrl: "app.component.html", styleUrls: ["app.component.scss"], }) export class AppComponent { constructor(private platform: Platform) { this.platform.ready().then(() => { const DOCUMENT = this.platform.is("ios") ? "Document.pdf" : "file:///android_asset/Document.pdf"; PSPDFKit.present(DOCUMENT); }); } }
-
The app is now ready to launch! Go back to the terminal and run:
ionic cordova emulate android
Next Steps
To learn more about Ionic, make sure to check out the following: