Skip to content

Commit cb2c9ea

Browse files
author
PSPDFKit
committed
Release 2.2.2
1 parent 6f6288b commit cb2c9ea

33 files changed

+328
-208
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
## Newest Release
22

3+
### 2.2.2 - 15 Mar 2022
4+
5+
- Adds image support to `PSKDFKit.present()` on Android. (#33312)
6+
- Adds a new **Save As** example to the Catalog example project. (#33376)
7+
- Updates for PSPDFKit 11.3.0 for iOS. (#33485)
8+
- Fixes React Native Annotation Processor API for Android. (#33189, #33302)
9+
10+
## Previous Releases
11+
312
### 2.2.1 - 04 Mar 2022
413

514
- Updates for PSPDFKit 8.1.2 for Android. (#33315)
615
- Updates for PSPDFKit 11.2.4 for iOS. (#33315)
716
- Fixes React Native Annotation Processor Catalog example for Android.(#33189)
817

9-
## Previous Releases
10-
1118
### 2.2.0 - 14 Feb 2022
1219

1320
- This release requires you to update your Android project's `compileSdkVersion` to version 31. Please refer to [our migration guide](https://pspdfkit.com/guides/react-native/migration-guides/react-native-2-2-migration-guide) for this release.

android/src/main/java/com/pspdfkit/react/PSPDFKitModule.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public class PSPDFKitModule extends ReactContextBaseJavaModule implements Applic
6262

6363
private static final int REQUEST_CODE_TO_INDEX = 16;
6464
private static final int MASKED_REQUEST_CODE_TO_REAL_CODE = 0xffff;
65+
private static final String[] SUPPORTED_IMAGE_TYPES = new String[] {
66+
".jpg",
67+
".png",
68+
".jpeg",
69+
".tif",
70+
".tiff"
71+
};
72+
6573

6674
@Nullable
6775
private Activity resumedActivity;
@@ -103,6 +111,23 @@ public String getName() {
103111

104112
@ReactMethod
105113
public void present(@NonNull String document, @NonNull ReadableMap configuration, @Nullable Promise promise) {
114+
File documentFile = new File(document);
115+
if(isPdf(documentFile)) {
116+
lastPresentPromise = promise;
117+
presentPdf(document, configuration, promise);
118+
} else if(isImage(documentFile)) {
119+
lastPresentPromise = promise;
120+
presentImage(document, configuration, promise);
121+
}else {
122+
Throwable error = new Throwable("The document must be one of these file types: .pdf, .jpg, .png, .jpeg, .tif, .tiff");
123+
if (promise!=null){
124+
promise.reject(error);
125+
}
126+
}
127+
}
128+
129+
@ReactMethod
130+
public void presentPdf(@NonNull String document, @NonNull ReadableMap configuration, @Nullable Promise promise) {
106131
if (getCurrentActivity() != null) {
107132
if (resumedActivity == null) {
108133
// We register an activity lifecycle callback so we can get notified of the current activity.
@@ -118,7 +143,7 @@ public void present(@NonNull String document, @NonNull ReadableMap configuration
118143
PdfActivity.showDocument(getCurrentActivity(), Uri.parse(document), configurationAdapter.build());
119144
}
120145
}
121-
146+
122147
@ReactMethod
123148
public void presentImage(@NonNull String imageDocument, @NonNull ReadableMap configuration, @Nullable Promise promise) {
124149
if (getCurrentActivity() != null) {
@@ -202,7 +227,12 @@ public void processAnnotations(@NonNull final String processingMode,
202227
@NonNull final String sourceDocumentPath,
203228
@NonNull final String targetDocumentPath,
204229
@NonNull final Promise promise) {
205-
PdfDocumentLoader.openDocumentAsync(getReactApplicationContext(), Uri.parse(sourceDocumentPath))
230+
231+
// This is an edge case where file scheme is missing.
232+
String documentPath = Uri.parse(sourceDocumentPath).getScheme() == null
233+
? FILE_SCHEME + sourceDocumentPath : sourceDocumentPath;
234+
235+
PdfDocumentLoader.openDocumentAsync(getReactApplicationContext(), Uri.parse(documentPath))
206236
.flatMapCompletable(document -> {
207237
PdfProcessorTask task = PdfProcessorTask.fromDocument(document);
208238
final EnumSet<AnnotationType> types = ConversionHelpers.getAnnotationTypeFromString(annotationType);
@@ -344,4 +374,17 @@ public void run() {
344374
public void onNewIntent(Intent intent) {
345375
// Not required right now.
346376
}
377+
378+
private boolean isPdf(File file) {
379+
return file.getName().toLowerCase().endsWith(".pdf");
380+
}
381+
382+
private boolean isImage(File file) {
383+
for (String extension: SUPPORTED_IMAGE_TYPES) {
384+
if (file.getName().toLowerCase().endsWith(extension)) {
385+
return true;
386+
}
387+
}
388+
return false;
389+
}
347390
}

android/src/main/java/com/pspdfkit/react/ReactPdfViewManager.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,14 @@ public void onDropViewInstance(PdfView view) {
9292
@Nullable
9393
@Override
9494
public Map<String, Integer> getCommandsMap() {
95-
Map<String, Integer> commandMap = MapBuilder.of(
96-
"enterAnnotationCreationMode",
97-
COMMAND_ENTER_ANNOTATION_CREATION_MODE,
98-
"exitCurrentlyActiveMode",
99-
COMMAND_EXIT_CURRENTLY_ACTIVE_MODE,
100-
"saveCurrentDocument",
101-
COMMAND_SAVE_CURRENT_DOCUMENT,
102-
"getAnnotations",
103-
COMMAND_GET_ANNOTATIONS,
104-
"addAnnotation",
105-
COMMAND_ADD_ANNOTATION,
106-
"getAllUnsavedAnnotations",
107-
COMMAND_GET_ALL_UNSAVED_ANNOTATIONS,
108-
"addAnnotations",
109-
COMMAND_ADD_ANNOTATIONS);
95+
Map<String, Integer> commandMap = MapBuilder.of();
96+
commandMap.put("enterAnnotationCreationMode", COMMAND_ENTER_ANNOTATION_CREATION_MODE);
97+
commandMap.put("exitCurrentlyActiveMode", COMMAND_EXIT_CURRENTLY_ACTIVE_MODE);
98+
commandMap.put("saveCurrentDocument", COMMAND_SAVE_CURRENT_DOCUMENT);
99+
commandMap.put("getAnnotations", COMMAND_GET_ANNOTATIONS);
100+
commandMap.put("addAnnotation", COMMAND_ADD_ANNOTATION);
101+
commandMap.put("getAllUnsavedAnnotations", COMMAND_GET_ALL_UNSAVED_ANNOTATIONS);
102+
commandMap.put("addAnnotations", COMMAND_ADD_ANNOTATIONS);
110103
commandMap.put("getFormFieldValue", COMMAND_GET_FORM_FIELD_VALUE);
111104
commandMap.put("setFormFieldValue", COMMAND_SET_FORM_FIELD_VALUE);
112105
commandMap.put("removeAnnotation", COMMAND_REMOVE_ANNOTATION);

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class PSPDFKitView extends React.Component {
101101
this._requestMap.delete(requestId);
102102
};
103103

104-
105104
/**
106105
* Enters the annotation creation mode, showing the annotation creation toolbar.
107106
*/
@@ -508,22 +507,21 @@ class PSPDFKitView extends React.Component {
508507

509508
/**
510509
* Removes the currently displayed Android Native PdfUiFragment.
511-
*
510+
*
512511
* This function should only be used as a workaround for a bug in `react-native-screen` that causes a crash when
513-
* `navigation.goBack()` is called or a hardware back button is used to navigate back on Android. Calling this
512+
* `navigation.goBack()` is called or a hardware back button is used to navigate back on Android. Calling this
514513
* function will prevent the crash by removing the fragment from the `PdfView` before the navigation takes place.
515-
*
514+
*
516515
* <b>Note:</> this function is available for Android only, it will have no effect on iOS.
517516
*/
518-
destroyView = function () {
517+
destroyView = function () {
519518
if (Platform.OS === "android") {
520519
UIManager.dispatchViewManagerCommand(
521520
findNodeHandle(this.refs.pdfView),
522-
this._getViewManagerConfig("RCTPSPDFKitView").Commands
523-
.removeFragment,
521+
this._getViewManagerConfig("RCTPSPDFKitView").Commands.removeFragment,
524522
[]
525523
);
526-
}
524+
}
527525
};
528526

529527
_getViewManagerConfig = (viewManagerName) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "React Native PDF Library by PSPDFKit",
55
"keywords": [
66
"react native",

samples/Catalog/.watchmanconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

samples/Catalog/Catalog.js

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,39 @@
88

99
// Imports
1010
import React, {Component} from 'react';
11-
import {FlatList, Image, processColor, StyleSheet, Text, TouchableHighlight, View} from 'react-native';
11+
import {
12+
FlatList,
13+
Image,
14+
processColor,
15+
StyleSheet,
16+
Text,
17+
TouchableHighlight,
18+
View,
19+
} from 'react-native';
1220
import {createStackNavigator} from 'react-navigation-stack';
1321
import {createAppContainer} from 'react-navigation';
1422

15-
import {exampleDocumentName, exampleDocumentPath, pspdfkitColor, tiffImagePath} from "./configuration/Constants";
16-
import {extractFromAssetsIfMissing} from "./helpers/FileSystemHelpers";
17-
import {PSPDFKitViewComponent} from "./examples/PSPDFKitViewComponent";
18-
import {OpenImageDocument} from "./examples/OpenImageDocument";
19-
import {ManualSave} from "./examples/ManualSave";
20-
import {EventListeners} from "./examples/EventListeners";
21-
import {StateChange} from "./examples/StateChange";
22-
import {PSPDFKit} from "./helpers/PSPDFKit";
23-
import {AnnotationProcessing} from "./examples/AnnotationProcessing";
24-
import {ProgrammaticAnnotations} from "./examples/ProgrammaticAnnotations";
25-
import {ProgrammaticFormFilling} from "./examples/ProgrammaticFormFilling";
26-
import {SplitPDF} from "./examples/SplitPDF";
27-
import {ToolbarCustomization} from "./examples/ToolbarCustomization";
28-
import {HiddenToolbar} from "./examples/HiddenToolbar";
29-
import {CustomFontPicker} from "./examples/CustomFontPicker";
23+
import {
24+
exampleDocumentName,
25+
exampleDocumentPath,
26+
pspdfkitColor,
27+
tiffImagePath,
28+
} from './configuration/Constants';
29+
import {extractFromAssetsIfMissing} from './helpers/FileSystemHelpers';
30+
import {PSPDFKitViewComponent} from './examples/PSPDFKitViewComponent';
31+
import {OpenImageDocument} from './examples/OpenImageDocument';
32+
import {SaveAs} from './examples/SaveAs';
33+
import {ManualSave} from './examples/ManualSave';
34+
import {EventListeners} from './examples/EventListeners';
35+
import {StateChange} from './examples/StateChange';
36+
import {PSPDFKit} from './helpers/PSPDFKit';
37+
import {AnnotationProcessing} from './examples/AnnotationProcessing';
38+
import {ProgrammaticAnnotations} from './examples/ProgrammaticAnnotations';
39+
import {ProgrammaticFormFilling} from './examples/ProgrammaticFormFilling';
40+
import {SplitPDF} from './examples/SplitPDF';
41+
import {ToolbarCustomization} from './examples/ToolbarCustomization';
42+
import {HiddenToolbar} from './examples/HiddenToolbar';
43+
import {CustomFontPicker} from './examples/CustomFontPicker';
3044

3145
const fileSystem = require('react-native-fs');
3246

@@ -95,6 +109,16 @@ const examples = [
95109
},
96110
{
97111
key: 'item4',
112+
name: 'Save As',
113+
description: 'Save changes to the PDF in a separate file',
114+
action: component => {
115+
extractFromAssetsIfMissing(exampleDocumentName, function () {
116+
component.props.navigation.push('SaveAs');
117+
});
118+
},
119+
},
120+
{
121+
key: 'item5',
98122
name: 'Event Listeners',
99123
description:
100124
'Show how to use the listeners exposed by the PSPDFKitView component.',
@@ -103,16 +127,16 @@ const examples = [
103127
},
104128
},
105129
{
106-
key: 'item5',
130+
key: 'item6',
107131
name: 'Changing the State',
108132
description:
109133
'Add a toolbar at the bottom with buttons to toggle the annotation toolbar, and to programmatically change pages.',
110134
action: component => {
111135
component.props.navigation.push('StateChange');
112136
},
113137
},
114-
{
115-
key: 'item6',
138+
{
139+
key: 'item7',
116140
name: 'Annotation Processing',
117141
description:
118142
'Show how to embed, flatten, remove, and print annotations; then present the newly processed document.',
@@ -123,15 +147,15 @@ const examples = [
123147
},
124148
},
125149
{
126-
key: 'item7',
150+
key: 'item8',
127151
name: 'Programmatic Annotations',
128152
description: 'Show how to get and add new annotations using Instant JSON.',
129153
action: component => {
130154
component.props.navigation.push('ProgrammaticAnnotations');
131155
},
132156
},
133157
{
134-
key: 'item8',
158+
key: 'item9',
135159
name: 'Programmatic Form Filling',
136160
description:
137161
'Show how to get the value of a form element and how to programmatically fill forms.',
@@ -140,7 +164,7 @@ const examples = [
140164
},
141165
},
142166
Platform.OS === 'ios' && {
143-
key: 'item9',
167+
key: 'item10',
144168
name: 'Split PDF',
145169
description:
146170
'Show two PDFs side by side by using multiple PSPDFKitView components.',
@@ -149,15 +173,15 @@ const examples = [
149173
},
150174
},
151175
Platform.OS === 'ios' && {
152-
key: 'item10',
176+
key: 'item11',
153177
name: 'Customize the Toolbar',
154178
description: 'Show how to customize buttons in the toolbar.',
155179
action: component => {
156180
component.props.navigation.push('ToolbarCustomization');
157181
},
158182
},
159183
{
160-
key: 'item11',
184+
key: 'item12',
161185
name: 'Hidden Toolbar',
162186
description:
163187
'Hide the main toolbar while keeping the thumbnail bar visible.',
@@ -166,7 +190,7 @@ const examples = [
166190
},
167191
},
168192
{
169-
key: 'item12',
193+
key: 'item13',
170194
name: 'Custom Font Picker',
171195
description:
172196
'Show how to customize the font picker for free text annotations.',
@@ -176,7 +200,7 @@ const examples = [
176200
},
177201
/// Present examples.
178202
{
179-
key: 'item13',
203+
key: 'item14',
180204
name: 'Open a Document Using the Native Module API',
181205
description:
182206
'Open a document using the Native Module API by passing its path.',
@@ -193,7 +217,7 @@ const examples = [
193217
},
194218
},
195219
{
196-
key: 'item14',
220+
key: 'item15',
197221
name: 'Customize Document Configuration',
198222
description:
199223
'Customize various aspects of the document by passing a configuration dictionary.',
@@ -202,18 +226,13 @@ const examples = [
202226
},
203227
},
204228
{
205-
key: 'item15',
229+
key: 'item16',
206230
name: 'Open an Image Document Using the Native Module API',
207231
description:
208232
'Open an image document using the Native Module API. Supported filetypes are PNG, JPEG and TIFF.',
209233
action: () => {
210234
// PSPDFKit can open PNG, JPEG and TIFF image files directly.
211-
if (Platform.OS === 'ios') {
212-
PSPDFKit.present(tiffImagePath, tiffImageConfiguration);
213-
}
214-
if (Platform.OS === 'android') {
215-
PSPDFKit.presentImage(tiffImagePath, tiffImageConfiguration);
216-
}
235+
PSPDFKit.present(tiffImagePath, tiffImageConfiguration);
217236
},
218237
},
219238
];
@@ -266,8 +285,7 @@ class Catalog extends Component {
266285
item.action(this);
267286
}}
268287
style={styles.row}
269-
underlayColor={pspdfkitColor}
270-
>
288+
underlayColor={pspdfkitColor}>
271289
<View style={styles.rowContent}>
272290
<Text style={styles.name}>{item.name}</Text>
273291
<Text style={styles.description}>{item.description}</Text>
@@ -292,6 +310,9 @@ export default createAppContainer(
292310
ManualSave: {
293311
screen: ManualSave,
294312
},
313+
SaveAs: {
314+
screen: SaveAs,
315+
},
295316
EventListeners: {
296317
screen: EventListeners,
297318
},
@@ -366,4 +387,3 @@ var styles = StyleSheet.create({
366387
padding: 10,
367388
},
368389
});
369-

0 commit comments

Comments
 (0)