|
@@ -8,7 +8,7 @@
|
|
|
*/
|
|
|
|
|
|
import React, { useState, useEffect, useRef } from 'react';
|
|
|
-import { Image, Platform, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
|
+import { Image, Platform, StyleSheet, Text, View } from 'react-native';
|
|
|
import { CPDFReaderView, ComPDFKit, CPDFToolbarAction } from '@compdfkit_pdf_sdk/react_native';
|
|
|
import { useNavigation, useRoute, RouteProp } from '@react-navigation/native';
|
|
|
import { HeaderBackButton } from '@react-navigation/elements';
|
|
@@ -25,7 +25,7 @@ type CPDFReaderViewExampleScreenRouteProp = RouteProp<
|
|
|
'CPDFReaderViewExample'
|
|
|
>;
|
|
|
|
|
|
-const CPDFReaderViewConctrolExampleScreen = () => {
|
|
|
+const CPDFReaderViewControllerExampleScreen = () => {
|
|
|
|
|
|
const pdfReaderRef = useRef<CPDFReaderView>(null);
|
|
|
|
|
@@ -100,38 +100,37 @@ const CPDFReaderViewConctrolExampleScreen = () => {
|
|
|
|
|
|
// Android
|
|
|
// import xfdf file from android assets directory
|
|
|
- // const testXfdf = Platform.OS === 'android'
|
|
|
- // ? 'file:///android_asset/test.xfdf'
|
|
|
- // : 'test.xfdf'
|
|
|
+ // const testXfdf = Platform.OS === 'android'
|
|
|
+ // ? 'file:///android_asset/test.xfdf'
|
|
|
+ // : 'test.xfdf'
|
|
|
// import xfdf file from file path
|
|
|
- // const testXfdf = '/data/user/0/com.compdfkit.reactnative.example/xxx/xxx.xfdf';
|
|
|
+ // const testXfdf = '/data/user/0/com.compdfkit.reactnative.example/xxx/xxx.xfdf';
|
|
|
|
|
|
- // const importResult = await pdfReaderRef.current?.importAnnotations(testXfdf);
|
|
|
- // console.log('ComPDFKitRN importAnnotations:', importResult);
|
|
|
+ // const importResult = await pdfReaderRef.current?.importAnnotations(testXfdf);
|
|
|
+ // console.log('ComPDFKitRN importAnnotations:', importResult);
|
|
|
|
|
|
|
|
|
// Select an xfdf file from the public directory and import it into the current document
|
|
|
- const pickerResult = DocumentPicker.pick({
|
|
|
- type: [DocumentPicker.types.allFiles],
|
|
|
- copyTo: 'cachesDirectory'
|
|
|
- });
|
|
|
- pickerResult.then(async (res) => {
|
|
|
- const file = res[0];
|
|
|
- const fileName = file?.name;
|
|
|
- // if(!fileName?.endsWith('xfdf')){
|
|
|
- // console.log('ComPDFKitRN please select xfdf format file');
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
- console.log('fileUri:' , file?.uri);
|
|
|
- console.log('fileCopyUri:' , file?.fileCopyUri);
|
|
|
- console.log('fileType:' , file?.type);
|
|
|
- const path = file!!.fileCopyUri!!
|
|
|
-
|
|
|
- const importResult = await pdfReaderRef.current?.importAnnotations(path);
|
|
|
- console.log('ComPDFKitRN importAnnotations:', importResult);
|
|
|
-
|
|
|
- })
|
|
|
+ const pickerResult = DocumentPicker.pick({
|
|
|
+ type: [DocumentPicker.types.allFiles],
|
|
|
+ copyTo: 'cachesDirectory'
|
|
|
+ });
|
|
|
+ pickerResult.then(async (res) => {
|
|
|
+ const file = res[0];
|
|
|
+ const fileName = file?.name;
|
|
|
+ if (!fileName?.endsWith('xfdf')) {
|
|
|
+ console.log('ComPDFKitRN please select xfdf format file');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('fileUri:', file?.uri);
|
|
|
+ console.log('fileCopyUri:', file?.fileCopyUri);
|
|
|
+ console.log('fileType:', file?.type);
|
|
|
+ const path = file!!.fileCopyUri!!
|
|
|
+
|
|
|
+ const importResult = await pdfReaderRef.current?.importAnnotations(path);
|
|
|
+ console.log('ComPDFKitRN importAnnotations:', importResult);
|
|
|
+ })
|
|
|
} catch (err) {
|
|
|
}
|
|
|
break;
|
|
@@ -140,22 +139,18 @@ const CPDFReaderViewConctrolExampleScreen = () => {
|
|
|
console.log('ComPDFKitRN exportAnnotations:', exportXfdfFilePath);
|
|
|
break;
|
|
|
case 'setMargins':
|
|
|
- await pdfReaderRef.current?.setMargins(10,20,10,20)
|
|
|
+ await pdfReaderRef.current?.setMargins(10, 20, 10, 20)
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
const renderToolbar = () => {
|
|
|
return (
|
|
|
-
|
|
|
-
|
|
|
<View style={styles.toolbar}>
|
|
|
<HeaderBackButton onPress={handleBack} />
|
|
|
- <Text style={styles.toolbarTitle}>Control Example</Text>
|
|
|
+ <Text style={styles.toolbarTitle}>Controller Example</Text>
|
|
|
|
|
|
<Menu>
|
|
|
<MenuTrigger>
|
|
@@ -171,11 +166,10 @@ const CPDFReaderViewConctrolExampleScreen = () => {
|
|
|
</MenuOptions>
|
|
|
</Menu>
|
|
|
</View>
|
|
|
-
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- const onPageChanged = (pageIndex : number) =>{
|
|
|
+ const onPageChanged = (pageIndex: number) => {
|
|
|
console.log('ComPDFKitRN --- onPageChanged:', pageIndex);
|
|
|
}
|
|
|
|
|
@@ -200,12 +194,11 @@ const CPDFReaderViewConctrolExampleScreen = () => {
|
|
|
CPDFToolbarAction.THUMBNAIL
|
|
|
]
|
|
|
}
|
|
|
- })}/>
|
|
|
+ })} />
|
|
|
</View>
|
|
|
</SafeAreaView>
|
|
|
</MenuProvider>
|
|
|
);
|
|
|
-
|
|
|
};
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
@@ -234,7 +227,7 @@ const styles = StyleSheet.create({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
-export default CPDFReaderViewConctrolExampleScreen;
|
|
|
+export default CPDFReaderViewControllerExampleScreen;
|
|
|
|
|
|
|
|
|
|