The PSPDFKit SDK is a framework that allows you to view, annotate, sign, and fill PDF forms on iOS, Android, Windows, macOS, and Web.
PSPDFKit comes with open source plugins for Cordova on both iOS and Android.
- Xcode 11 or later
- PSPDFKit 9.0.0 for iOS or later
- Cordova >= 9.0.0
- CocoaPods >= 1.8.1
We assume that you have an existing Cordova project.
- Run
cordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
to install thepspdfkit-cordova
plugin. - Update your
Podfile
:cd platforms/ios
and open yourPodfile
in a text editor. Make sure the platorm is set to iOS 11 or later, and replaceYOUR_COCOAPODS_KEY_GOES_HERE
with your own CocoaPods Key. YourPodfile
should look like this:
source 'https://github.com/CocoaPods/Specs.git'
- platform :ios, '9.0'
+ platform :ios, '11.0'
use_frameworks!
target 'CordovaDemo' do
project 'CordovaDemo.xcodeproj'
- pod 'PSPDFKit', podspec: 'https://customers.pspdfkit.com/cocoapods/YOUR_COCOAPODS_KEY_GOES_HERE/pspdfkit/latest.podspec'
+ pod 'PSPDFKit', podspec: 'https://customers.pspdfkit.com/cocoapods/USE_YOUR_OWN_COCOAPODS_KEY/pspdfkit/latest.podspec'
end
- If your application is targeting iOS versions prior to iOS 12.2 and your application does not already contain any Swift code, then you need to make sure Xcode bundles Swift standard libraries with your application distribution. To to so, open your target Build Settings and enable
Always Embed Swift Standard Libraries
:
Important If you’re an existing customer, you can find the CocoaPods and license keys in your customer portal. Otherwise, if you don’t already have PSPDFKit, sign up for our 60-day trial and you will receive an email with the instructions to get started.
- Install the Pods: run
pod install
.
The plugin is accessed via the PSPDFKit singleton. Here are some example calls:
// Set your license key here.
PSPDFKit.setLicenseKey("YOUR KEY");
// Show pdf with in single page mode, with a cblack background.
PSPDFKit.present("pdf/document.pdf", {
pageMode: "single",
backgroundColor: "black"
});
// Show a PDF document with a callback.
PSPDFKit.present("pdf/document.pdf", function() {
alert("pdf has appeared");
});
// Scroll to page 1.
PSPDFKit.setPage(1, true);
// Get the page number.
PSPDFKit.getPage(function(page) {
alert("Current page: " + page);
});
Let's create a simple Corodva app that integrates PSPDFKit and uses the pspdfkit-cordova
plugin.
- Run
cordova create Cordova-Demo com.pspdfkit.demo CordovaDemo
to create a new Cordova project. - Add a sample PDF into your
www
directory:www/pdf/document.pdf
. - Modify the
onDeviceReady
function inwww/js/index.js
like so:
onDeviceReady: function() {
this.receivedEvent('deviceready');
// Set your license key here.
PSPDFKit.setLicenseKey("YOUR KEY");
// Show pdf with in single page mode.
PSPDFKit.present('pdf/document.pdf', {
pageMode: 'single',
});
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
cd
intoCordova-Demo
and runcordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
to install thepspdfkit-cordova
plugin.- Open
config.xml
and change the deployment target to iOS 11 or later:
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
+ <preference name="deployment-target" value="11.0" />
</platform>
- Use your CocoaPods Key:
open plugins/pspdfkit-cordova/plugin.xml
and replaceYOUR_COCOAPODS_KEY_GOES_HERE
with your own key. If you’re an existing customer, you can find the CocoaPods and license keys in your customer portal. Otherwise, if you don’t already have PSPDFKit, sign up for our 60-day trial and you will receive an email with the instructions to get started. - Run
cordova platform add ios
to add the iOS platform. - If your application is targeting iOS versions prior to iOS 12.2 and your application does not already contain any Swift code, then you need to make sure Xcode bundles Swift standard libraries with your application distribution. To to so, open your target Build Settings and enable
Always Embed Swift Standard Libraries
:
- Run the app: Open
platforms/ios/CordovaDemo.xcworkspace
in Xcode, then build and run, or runcordova emulate ios
in the Terminal.
Let's create a simple Ionic app that integrates PSPDFKit and uses the pspdfkit-cordova
plugin.
- Run
ionic start IonicDemo blank --type=angular
to create a new Ionic project. cd
intoIonicDemo
and runionic cordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
to install thepspdfkit-cordova
plugin.- Add a sample PDF into your
www
directory:www/pdf/document.pdf
. - Open
config.xml
and change the deployment target to iOS 11 or later:
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
+ <allow-navigation href="*" />
+ <preference name="deployment-target" value="11.0" />
</platform>
-
Use your CocoaPods Key:
open plugins/pspdfkit-cordova/plugin.xml
and replaceYOUR_COCOAPODS_KEY_GOES_HERE
with your own key. If you’re an existing customer, you can find the CocoaPods and license keys in your customer portal. Otherwise, if you don’t already have PSPDFKit, sign up for our 60-day trial and you will receive an email with the instructions to get started. -
Declare
PSPDFKit
insrc/declarations.d.ts
(create this file first):declare var PSPDFKit: any;
-
Modifying
src/app/app.component.ts
to use the PSPDFKit plugin to Present a PDF:
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
PSPDFKit.setLicenseKey('YOUR KEY');
PSPDFKit.present('pdf/document.pdf', {});
});
}
- Run
ionic cordova platform add ios
to add the iOS platform. - Run
ionic cordova prepare ios
to prepare iOS platform. - If your application is targeting iOS versions prior to iOS 12.2 and your application does not already contain any Swift code, then you need to make sure Xcode bundles Swift standard libraries with your application distribution. To to so, open your target Build Settings and enable
Always Embed Swift Standard Libraries
:
11. Run the app: Open platforms/ios/MyApp.xcworkspace
in Xcode, then build and run, or run ionic cordova emulate ios
in the Terminal.
You can find the API documentation in PSPDFKit.js.
Using cordova-fetch for cordova-ios@^5.0.0
Adding ios project...
Creating Cordova project for the iOS platform:
Path: platforms/ios
Package: com.pspdfkit.demo
Name: CordovaDemo
iOS project created with [email protected]
Installing "pspdfkit-cordova" for ios
Running command: pod install --verbose
Failed to install 'pspdfkit-cordova': Error: pod: Command failed with exit code 1
at ChildProcess.whenDone (/Users/radazzouz/Downloads/Cordova-Demo/node_modules/cordova-common/src/superspawn.js:135:23)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
pod: Command failed with exit code 1
Use your CocoaPods Key: open plugins/pspdfkit-cordova/plugin.xml
and replace YOUR_COCOAPODS_KEY_GOES_HERE
with your own key. If you’re an existing customer, you can find the CocoaPods and license keys in your customer portal. Otherwise, if you don’t already have PSPDFKit, sign up for our 60-day trial and you will receive an email with the instructions to get started.
Error: Cannot find plugin.xml for plugin "PSPDFKit-Cordova". Please try adding it again.
Run cordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
instead of ionic cordova plugin add https://github.com/PSPDFKit/PSPDFKit-Cordova.git
.
If you were using the old Cordova-iOS Plugin, please follow the steps below to migrate to this plugin:
- Remove the old plugin:
cordova plugin remove pspdfkit-cordova-ios
- Open your Xcode project or workspace and remove
PSPDFKit.framework
andPSPDFKitUI.framework
from your Target:
- Close your Xcode project or workspace.
- Integrate the new
pspdfkit-cordova
Plugin. See the Install instructions above. - Rename all
PSPDFKitPlugin
calls toPSPDFKit
in your app's JavaScript code:
- PSPDFKitPlugin.setLicenseKey("YOUR KEY");
+ PSPDFKit.setLicenseKey("YOUR KEY");
- PSPDFKitPlugin.present('pdf/document.pdf', {
+ PSPDFKit.present('pdf/document.pdf', {
pageMode: 'single',
});