Frameworks
React Native
Flutter
Package samples
Cookbook
Version 11
Version 10
Version 9
Version 8
Version 7
Version 6
Version 5
## Introduction
The React Native API for Apryse Mobile SDK includes all of the most used functions and methods for viewing, annotating and saving PDF documents. However, it is possible your app may need access to APIs that are available as part of the native API, but are not directly available to React Native.
This guide provides an example of how to add the following to the React Native interface:
pageChangeOnTap
prop that determines whether page will turn left or right when tapping corresponding edges.getField
function which retrieves information about a field using its name.onLayoutChanged
event listener that is raised when the layout of viewer has changed.You can follow the same pattern to add new functions and props that your React Native app may need. The new additions could be simple ones, which expose one piece of functionality, or custom ones, that expose a series of native commands under the hood.
Prior to following this guide, we highly recommend you to go through the official guide here: Native UI Components to have a better understanding of the system.
The source is hosted on GitHub here: https://github.com/ApryseSDK/pdftron-react-native
Fork the project and clone a copy of the repository to your disk.
pageChangeOnTap
propThe DocumentView.tsx
interface file lists all of the React Native props on the DocumentView component.
Add the prop declaration:
For props that accept Config
constants or arrays of Config
constants, use the oneOf
and arrayOf
helper methods. These helpers return flexible types that allow custom checks for TypeScript users, while maintaining standard run-time checks for all users.
Open file /android/src/main/java/com/pdftron/reactnative/viewmanagers/DocumentViewViewManager.java
.
Add the method key that matches the TS declaration:
Open file /android/src/main/java/com/pdftron/reactnative/views/DocumentView.java
.
Add the implementation:
The actual implementation will depend on the actual functionality.
getField
functionThe DocumentView.tsx
interface file lists all of the React Native functions on the DocumentView component.
Add the function declaration:
All functions return Promise<void | T>
where T
is the expected return type upon success. If the function returns void
upon success, simply put Promise<void>
.
While you are adding types, consider representing objects with reusable object types. You can use existing ones, or create a new type alias or interface in AnnotOptions.ts
(see Object Types).
Add this method to /android/src/main/java/com/pdftron/reactnative/modules/DocumentViewModule.java
:
Add the following to /android/src/main/java/com/pdftron/reactnative/viewmanagers/DocumentViewViewManager.java
:
Add the following to /android/src/main/java/com/pdftron/reactnative/views/DocumentView.java
:
The logic is to get the PDF view controller and if the field names are valid, use the controller to get the fields from the current document.
onLayoutChanged
event listenerEvent listeners are handled in DocumentView.tsx
. Add the following to the file:
The onLayoutChanged
event listener does not require any arguments. If your event listener requires arguments, access them using event.nativeEvent.exampleArg
.
For event listeners and other props that accept functions, use the func
helper method. This helper returns flexible types that allow custom checks for TypeScript users, while maintaining standard run-time checks for all users.
While you are adding types, consider representing objects with reusable object types. You can use existing ones, or create a new type alias or interface in AnnotOptions.ts
(see Object Types).
In android/src/main/java/com/pdftron/reactnative/utils/Constants.java
, add a constant to represent the event.
In /android/src/main/java/com/pdftron/reactnative/views/DocumentView.java
, create a new event listener to send the event to JS. This event listener will call the existing method onReceiveNativeEvent
when layout changes. Note that the event you want to implement may be a part of an existing event listener.
In the same file, /android/src/main/java/com/pdftron/reactnative/views/DocumentView.java
, add the event listener to our PDFViewCtrl
when the document has loaded, and remove the listener when it is no longer necessary.
The actual implementation will depend on the actual functionality.
Now npm install
your forked version to your application.
The new functionality is now ready to use.
The app can now access the new API as follows:
If you're only developing for Android, then you're all done!
If you're also deploying on iOS, you'll need to complete the necessary steps for iOS.
If you're developing for both iOS and Android, please consider submitting a PR, as upstreaming the change will simplify your developing and make the APIs available for other Apryse customers.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales