PSPDFKit Cordova 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
-
A development environment for running Cordova projects
-
The Android NDK
-
An Android Virtual Device or a hardware device
Creating a New Cordova 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 Cordova project by running the following command:
cordova create PSPDFKit-Demo com.pspdfkit.demo PSPDFKit-Demo
Installing the PSPDFKit Cordova Dependency
-
In the terminal, change the location of the current working directory inside the newly created project:
cd PSPDFKit-Demo
-
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"> + <preference name="AndroidXEnabled" value="true" /> <allow-intent href="market:*" /> </platform> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> + <preference name="deployment-target" value="15.0" /> ... </platform> ...
-
Add the PSPDFKit plugin:
cordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
-
Add the Android platform:
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
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
www/js/index.js
file:
open www/js/index.js
-
Modify the
onDeviceReady
function like so:
...
onDeviceReady: function() {
this.receivedEvent('deviceready');
+ const DOCUMENT = (window.cordova.platformId === "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:
cordova emulate android
Next Steps
To learn more about Cordova, make sure to check out the following: