From 1b1cad9918cc2611dfa08883c5471149a3bbcb1d Mon Sep 17 00:00:00 2001 From: PSPDFKit Date: Tue, 10 Sep 2024 17:31:04 +0200 Subject: [PATCH] Release 2.13.0 --- ACKNOWLEDGEMENTS.md | 60 + CHANGELOG.md | 21 +- README.md | 656 +- .../org.eclipse.buildship.core.prefs | 2 +- android/build.gradle | 18 +- .../react/AnnotationConfigurationAdaptor.kt | 214 +- .../com/pspdfkit/react/PDFDocumentModule.kt | 9 +- .../com/pspdfkit/react/PSPDFKitModule.java | 68 +- .../com/pspdfkit/react/PSPDFKitPackage.java | 2 +- .../pspdfkit/react/ReactPdfViewManager.java | 43 +- .../ReactAnnotationPresetConfiguration.kt | 11 + .../react/helper/ConversionHelpers.java | 168 +- .../main/java/com/pspdfkit/views/PdfView.java | 184 +- index.js | 157 +- ios/RCTPSPDFKit.xcodeproj/project.pbxproj | 4 + .../AnnotationConfigurationsConvertor.swift | 43 +- .../RCTConvert+PSPDFAnnotationType.swift | 78 + ios/RCTPSPDFKit/RCTPSPDFKitManager.m | 35 +- ios/RCTPSPDFKit/RCTPSPDFKitView.h | 2 + ios/RCTPSPDFKit/RCTPSPDFKitView.m | 40 + ios/RCTPSPDFKit/RCTPSPDFKitViewManager.m | 30 + lib/annotations/Annotation.js | 372 +- package-lock.json | 7994 ++++++----------- package.json | 2 +- react-native-pspdfkit.podspec | 4 +- samples/Catalog/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- .../AnnotationPresetCustomization.tsx | 42 +- .../Catalog/examples/AnnotationProcessing.tsx | 38 +- samples/Catalog/examples/Measurement.tsx | 1 + .../examples/ProgrammaticAnnotations.tsx | 29 +- samples/Catalog/examples/SaveAs.tsx | 7 +- samples/Catalog/examples/XFDF.tsx | 3 + samples/Catalog/ios/Podfile.lock | 20 +- samples/Catalog/package.json | 2 +- samples/Catalog/yarn.lock | 2 +- samples/NativeCatalog/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- samples/NativeCatalog/examples/GeneratePDF.js | 5 +- .../NativeCatalog/examples/InstantExample.js | 11 +- samples/NativeCatalog/examples/Watermark.js | 9 +- samples/NativeCatalog/ios/Podfile.lock | 30 +- samples/NativeCatalog/package.json | 2 +- samples/NativeCatalog/yarn.lock | 2 +- src/annotations/Annotation.ts | 750 +- types-scripts/native-modules.ts | 17 + types/index.d.ts | 55 +- types/index.d.ts.map | 2 +- yarn.lock | 5535 ++++++++++++ 49 files changed, 10745 insertions(+), 6047 deletions(-) create mode 100644 android/src/main/java/com/pspdfkit/react/annotations/ReactAnnotationPresetConfiguration.kt create mode 100644 ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotationType.swift create mode 100644 yarn.lock diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md index 49826c6f..1344a157 100644 --- a/ACKNOWLEDGEMENTS.md +++ b/ACKNOWLEDGEMENTS.md @@ -461,6 +461,36 @@ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. +-------------------------------------------------------------------------------- +// Copyright 2015 The Chromium Authors +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------------------------------------------------------------------------------- ## clipper2 (http://www.angusj.com/delphi/clipper.php) @@ -1731,6 +1761,36 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-------------------------------------------------------------------------------- +Copyright 2006 Google Inc. All Rights Reserved. +Author: agl@imperialviolet.org (Adam Langley) + +Copyright (C) 2006 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +This software is a description of processes which may be patented. + +Use of this software may require patent licenses in some countries. +You are directed to annex I of the JBIG2 specification for information. + +Some information could be found at: + http://www.jpeg.org/jbig/index.html + http://www.cl.cam.ac.uk/~mgk25/jbigkit/patents/ + http://www.jpeg.org/public/fcd14492.pdf + http://itscj.ipsj.or.jp/sc29/open/29view/29n55161.doc + + -------------------------------------------------------------------------------- ## koin (https://github.com/InsertKoinIO/koin) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b8ef4b..53ad4c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,31 @@ ## Newest Release +### 2.13.0 - 10 Sep 2024 + +- Adds TypeScript type support to the `annotationPresets` property on the `PSPDFKitView` component. (J#HYB-395) +- Adds support for a source document password to be specified when using the `processAnnotations` API. (J#HYB-453) +- Adds support to select and deselect annotations programmatically. (J#HYB-447) +- Updates to PSPDFKit 2024.5.1 for Android. +- Updates to PSPDFKit 13.9.1 for iOS. +- Fixes an issue where certain annotation presets weren't applied correctly. (J#HYB-395) +- Fixes an issue where custom toolbar buttons were not applied on the Android toolbar. (J#HYB-482) +- Fixes an issue where the `annotationTypes` parameter wasn't honored by the `processAnnotations` API. (J#HYB-495) +- Fixes an issue where the `onDocumentLoadFailed` callback was not triggered when an incorrect document password was specified on Android. (J#HYB-491) +- Fixes an issue where some measurement annotation presets were not applied when specified. (J#HYB-492) + +## Previous Releases + ### 2.12.0 - 01 Aug 2024 - Adds APIs belonging to the `PDFDocument` interface, moving them away from the global namespace. (J#HYB-406) -- Adds support for using `React.RefObject` as `PSPDFKitView` ref property. (J#HYB-444) +- Adds support for using `React.RefObject` as a `PSPDFKitView` ref property. (J#HYB-444) - Updates for PSPDFKit 2024.3.1 for Android. - Updates for PSPDFKit 13.8.0 for iOS. -- Fixes an issue where the `PSPDFKitView` sometimes failed to load the document on React Native Android. (J#HYB-397) +- Fixes an issue where `PSPDFKitView` sometimes failed to load the document on React Native Android. (J#HYB-397) - Fixes an issue where Instant JSON containing widgets was not applied using the `addAnnotations` API on iOS. (J#HYB-413) - Fixes an issue where password protected documents could not be saved after annotation changes were made. (J#HYB-454) - Fixes an issue where the `onDocumentLoaded` callback was not called reliably on iOS. (J#HYB-480) -## Previous Releases - ### 2.11.0 - 07 Jun 2024 - Adds the ability to clear the document cache. (J#HYB-347) diff --git a/README.md b/README.md index 1731c125..1b622050 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# React Native Library for PSPDFKit for iOS, Android & Windows UWP. (PDF SDK for React Native) +# React Native Library for PSPDFKit for iOS & Android (PDF SDK for React Native) ![PDF SDK for React Native](https://github.com/PSPDFKit/react-native/blob/master/article-header.png?raw=true) @@ -6,22 +6,7 @@ This library requires a valid license of PSPDFKit. Licenses are per platform. PSPDFKit for React Native exposes the most often used APIs from PSPDFKit. Many of our partners end up forking this repository and adding some custom code to achieve even greater integration with their products, using native code. -Windows is not currently supported, please use the previous version [1.24.9](https://github.com/PSPDFKit/react-native/releases/tag/1.24.9) instead. - -### Announcements - -- [Announcement blog post](https://pspdfkit.com/blog/2016/react-native-module/) -- [React Native UI Component for iOS](https://pspdfkit.com/blog/2018/react-native-ui-component-for-ios/) ([See iOS](https://github.com/PSPDFKit/react-native#ios)) -- [React Native UI Component for Android](https://pspdfkit.com/blog/2018/react-native-ui-component-for-android/) ([See Android](https://github.com/PSPDFKit/react-native#android)) -- [PSPDFKit for Windows UWP with React - Native](https://pspdfkit.com/blog/2018/introducing-pspdfkit-windows/#react-native-for-windows-support) ([See Windows UWP](https://github.com/PSPDFKit/react-native#windows-uwp)) -- [Advances in Hybrid Technologies](https://pspdfkit.com/blog/2019/advances-in-hybrid-technologies/) -- [How to Extend React Native APIs](https://pspdfkit.com/blog/2018/how-to-extend-react-native-api/) -- [Advanced Techniques for React Native UI Components](https://pspdfkit.com/blog/2018/advanced-techniques-for-react-native-ui-components/) -- [How to Extend React Native APIs for Windows](https://pspdfkit.com/blog/2019/how-to-extend-react-native-apis-for-windows/) -- [How to Bridge Native iOS Code to React Native](https://pspdfkit.com/blog/2020/how-to-bridge-native-ios-code-to-react-native/) -- [How to Open a PDF in React Native Using the Document Picker](https://pspdfkit.com/blog/2021/how-to-open-a-pdf-in-react-native-using-the-document-browser/) -- [How to Build a React Native PDF Viewer](https://pspdfkit.com/blog/2021/how-to-build-a-react-native-pdf-viewer/) +Windows is not currently supported, please use version [1.24.9](https://github.com/PSPDFKit/react-native/releases/tag/1.24.9) instead. ### PSPDFKit @@ -51,19 +36,30 @@ To set the license key for the currently running platform, use: PSPDFKit.setLicenseKey('YOUR_REACT_NATIVE_LICENSE_KEY_GOES_HERE'); ``` -## iOS - ### Requirements -- A [development environment](https://reactnative.dev/docs/environment-setup) for running React Native projects using the React Native CLI (not the Expo CLI) +- A [development environment](https://reactnative.dev/docs/environment-setup) for running React Native projects using the React Native CLI. If you’re using Expo, [check out our blog post](https://pspdfkit.com/blog/2023/how-to-use-pspdfkit-for-react-native-with-expo/) on the topic. + +#### iOS + - The [latest stable version of Xcode](https://apps.apple.com/us/app/xcode/id497799835?mt=12) - The [latest stable version of CocoaPods](https://github.com/CocoaPods/CocoaPods/releases). If you don’t already have CocoaPods installed, follow the [CocoaPods installation guide](https://guides.cocoapods.org/using/getting-started.html#installation) to install CocoaPods on your Mac. +#### Android + +- The [latest stable version of Android Studio](https://developer.android.com/studio) +- The [Android NDK](https://developer.android.com/studio/projects/install-ndk) +- An [Android Virtual Device](https://developer.android.com/studio/run/managing-avds.html) or a hardware device + +### Installation + +The PSPDFKit React Native dependency is installed from the GitHub repository and not the `npm` registry. To install the PSPDFKit React Native dependency, run `yarn add react-native-pspdfkit@github:PSPDFKit/react-native` in your project directory or `npm install github:PSPDFKit/react-native` if you’re using `npm`. + ### Getting Started -Let's create a simple app that integrates PSPDFKit and uses the `react-native-pspdfkit` module. +See our [Getting Started on React Native guide](https://pspdfkit.com/getting-started/react-native/?react-native-platform=android-ios&project=new-project) to integrate the SDK into your new or existing application, or follow the steps below: -1. In the terminal app, change the current working directory to the location you wish to save your project. In this example, we’ll use the `~/Documents/` directory: +1. In the terminal app, change the current working directory to the location you wish to save your project. In this example, we’ll use the `~/Documents` directory: ```bash cd ~/Documents @@ -72,7 +68,7 @@ Let's create a simple app that integrates PSPDFKit and uses the `react-native-ps 1. Create the React Native project by running the following command: ```bash - react-native init PSPDFKitDemo + npx react-native init PSPDFKitDemo ``` 1. In the terminal app, change the location of the current working directory inside the newly created project: @@ -84,7 +80,7 @@ Let's create a simple app that integrates PSPDFKit and uses the `react-native-ps 1. Add the PSPDFKit library: ```bash - yarn add github:PSPDFKit/react-native + yarn add react-native-pspdfkit@github:PSPDFKit/react-native ``` 1. Install all the dependencies for the project: @@ -93,52 +89,60 @@ Let's create a simple app that integrates PSPDFKit and uses the `react-native-ps yarn install ``` -1. Open your project’s Podfile in a text editor to update the platform to iOS 15, and add the PSPDFKit Podspec: +1. Open your project's `build.gradle` file: ```bash - open ios/Podfile + open android/build.gradle ``` - Your Podfile should look like this: - - ```diff - # Resolve react_native_pods.rb with node to allow for hoisting - require Pod::Executable.execute_command('node', ['-p', - 'require.resolve( - "react-native/scripts/react_native_pods.rb", - {paths: [process.argv[1]]}, - )', __dir__]).strip - - - platform :ios, '10.0' - + platform :ios, '15.0' - - target 'PSPDFKitDemo' do - config = use_native_modules! - - use_react_native!( - :path => config[:reactNativePath], - # to enable hermes on iOS, change `false` to `true` and then install pods - :hermes_enabled => false - ) - - target 'PSPDFKitDemoTests' do - inherit! :complete - # Pods for testing - end - + pod 'react-native-pspdfkit', :path => '../node_modules/react-native-pspdfkit' - + pod 'PSPDFKit', podspec: 'https://customers.pspdfkit.com/pspdfkit-ios/latest.podspec' - # Enables Flipper. - # - # Note that if you have use_frameworks! enabled, Flipper will not work and - # you should disable the next line. - use_flipper!() - - post_install do |installer| - react_native_post_install(installer, config[:reactNativePath]) - end - end +1. Add the PSPDFKit repository to download the PSPDFKit SDK: + + ```diff + allprojects { + repositories { + mavenLocal() + + maven { + + url 'https://my.pspdfkit.com/maven/' + + } + } + } + ``` + +1. Open the app’s build.gradle file: + + ```diff + ... + android { + - compileSdkVersion rootProject.ext.compileSdkVersion + + compileSdkVersion 34 + ... + defaultConfig { + applicationId "com.pspdfkitdemo" + - minSdkVersion rootProject.ext.minSdkVersion + + minSdkVersion 21 + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + } + } + ... + ``` + +1. Open your project’s Podfile: + + ```bash + open ios/Podfile ``` +1. Update the minimum iOS platform version in the Podfile: + + ```diff + ... + - platform :ios, min_ios_version_supported + + platform :ios, '15.0' + ... + ``` + 1. Change the location of the current working directory to the `ios` folder: ```bash @@ -175,515 +179,87 @@ Let's create a simple app that integrates PSPDFKit and uses the `react-native-ps cd .. ``` -1. Open your `App.js` file: - - ```bash - open App.js - ``` - -1. Replace the entire contents of `App.js` with the following code snippet: - - ```js - import React, { Component } from 'react'; - import { Platform } from 'react-native'; - import PSPDFKitView from 'react-native-pspdfkit'; - - const DOCUMENT = - Platform.OS === 'ios' - ? 'Document.pdf' - : 'file:///android_asset/Document.pdf'; - export default class PSPDFKitDemo extends Component<{}> { - render() { - return ( - - ); - } - } - ``` - -1. The app is now ready to launch! Go back to the terminal app and run: - - ```bash - react-native run-ios - ``` - -## Usage - -There are 2 different ways on how to use PSPDFKit for React Native on iOS. - -- Present a document via a Native Module modally. -- Show a PSPDFKit view via a Native UI component. - -Depending on your needs you might want to use one or the other. - -## Native Module - -Using the Native Module `PSPDFKit.present()`, you can present a document with PSPDFKit modally in fullscreen. -You can specify the path to the document you want to present, and [configuration options](#configuration). - -```javascript -import React, { Component } from 'react'; -import { NativeModules, Text, TouchableHighlight, View } from 'react-native'; - -export default class App extends Component<{}> { - _onPressButton() { - PSPDFKit.present('document.pdf', { - pageTransition: 'scrollContinuous', - scrollDirection: 'vertical', - documentLabelEnabled: true, - }); - } - - render() { - return ( - - - Tap to Open Document - - - ); - } -} -``` - -## Native UI Component - -With `PSPDFKitView` you can use PSPDFKit like any other React component in your app. -Using this approach, you have more flexibility over how a document is presented and displayed. - -The layout is completely flexible, and can be adjust with flexbox. - -For all the `props` that you can pass to `PSPDFKitView`, have a look at the [source documentation](./index.js). - -This is how you would show a PDF as a React component: - -```javascript -import React, { Component } from 'react'; -import { NativeModules } from 'react-native'; -import PSPDFKitView from 'react-native-pspdfkit'; - -export default class App extends Component<{}> { - render() { - return ( - - ); - } -} -``` - -### Configuration - -You can configure the presentation with a configuration dictionary which is a mirror of the [`PSPDFConfiguration`](https://pspdfkit.com/api/ios/Classes/PSPDFConfiguration.html) class. - -Example - Native Module: - -```javascript -PSPDFKit.present('document.pdf', { - showThumbnailBar: 'scrollable', - pageTransition: 'scrollContinuous', - scrollDirection: 'vertical', -}); -``` - -Example - Native UI Component: - -```javascript - -``` - -### Running the Catalog Project - -Take a look at the [instructions to get started here](/samples/Catalog/README.md#running-the-catalog-on-ios). - -### Running the Native Catalog - -Take a look at the [instructions to get started here](/samples/NativeCatalog/README.md#running-this-sample-on-ios). - -### Running on Mac Catalyst - -Using PSPDFKit for React Native on Mac Catalyst does not currently work due to a [Flipper and FlipperKit issue](https://github.com/facebook/react-native/issues/28810). - -If you wish to run your project on Mac Catalyst, please try the [following workaround which removes everything related to Flipper and FlipperKit](https://github.com/facebook/react-native/issues/28810#issuecomment-623357732). - -### Configuration Mapping - -On iOS, PSPDFKit for React Native iOS maps most configuration options available in `PSPDFConfiguration` from JSON. Take a look at the [list of all configuration options](/documentation/configuration-options.md) for more information. For the iOS-specific implementation, check out [`RCTConvert+PSPDFConfiguration.m`](./ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFConfiguration.m#L267) for the complete list and for the exact naming of enum values. - -Annotations are mapped based on their type name. This is case sensitive. For example, to limit annotation types to ink and highlight, use this: - -```javascript -editableAnnotationTypes: ['Ink', 'Highlight']; -``` - -### Menu Item Mapping - -On iOS, PSPDFKit for React Native allows you to specify a custom grouping for the annotation creation toolbar. Please refer to [`RCTConvert+PSPDFAnnotationToolbarConfiguration.m`](./ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFAnnotationToolbarConfiguration.m#L47) for the complete list of menu items. To set them just specify the `menuItemGrouping` prop on the `PSPDFKitView`. The format used is as follows: - -```javascript -[ - menuItem, - { key: menuItem, items: [subItem, subItem]}, - ... -] -``` - -### Customize the Toolbar Buttons - -You can customize the toolbar buttons on the Native UI View component by specifying the toolbar buttons using `setLeftBarButtonItems` and `setRightBarButtonItems`, like so: - -```javascript -pdfView.setRightBarButtonItems( - ['thumbnailsButtonItem', 'searchButtonItem', 'annotationButtonItem'], - 'document', - false, -); -``` - -Please refer to [`RCTConvert+UIBarButtonItem.m`](./ios/RCTPSPDFKit/Converters/RCTConvert%2BUIBarButtonItem.m#L14) for the complete list of bar button items. - -Also, please take a look at the [ToolbarCustomization example from our Catalog app](./samples/Catalog/Catalog.js). - -For a more detailed description of toolbar customizations, refer to our Customizing the Toolbar guide for [iOS](https://pspdfkit.com/guides/ios/current/customizing-the-interface/customizing-the-toolbar/) and [Android](https://pspdfkit.com/guides/android/current/customizing-the-interface/customizing-the-toolbar/). - -### Process Annotations - -PSPDFKit for React Native allows you to create a new document with processed (embedded, flattenned, removed, or printed) annotations on Android and iOS using the `PSPDFKit.processAnnotations(annotationChange, annotationType, sourceDocumentPath, processedDocumentPath)` function. In the snippet below, we add a button which flattens all the annotations of the document from the currently displayed `PSPDFKitView` in a newly processed PDF file: - -```javascript - -