|
@@ -16,6 +16,7 @@ import { MenuProvider, Menu, MenuTrigger, MenuOptions, MenuOption } from 'react-
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
import RNFS from 'react-native-fs';
|
|
|
import { CPDFImportDocumentScreen } from './screens/CPDFImportDocumentScreen';
|
|
|
+import { CPDFFileUtil } from './util/CPDFFileUtil';
|
|
|
|
|
|
type RootStackParamList = {
|
|
|
CPDFReaderViewExample: { document?: string };
|
|
@@ -69,17 +70,19 @@ const CPDFPagesExampleScreen = () => {
|
|
|
case 'Split Document':
|
|
|
// const uri = await ComPDFKit.createUri('split_document_test.pdf', '', 'application/pdf')
|
|
|
|
|
|
- const appCacheDirectory = RNFS.CachesDirectoryPath;
|
|
|
- const savePath = appCacheDirectory + '/split_document_test.pdf';
|
|
|
+ const fileUtil = new CPDFFileUtil();
|
|
|
+ const baseName = 'split_document_test';
|
|
|
+ const extension = 'pdf';
|
|
|
+ const uniqueFilePath = await fileUtil.getUniqueFilePath(baseName, extension);
|
|
|
|
|
|
const pages = [0];
|
|
|
const splitResult = await pdfReaderRef.current?._pdfDocument.splitDocumentPages(
|
|
|
- savePath, pages
|
|
|
+ uniqueFilePath, pages
|
|
|
)
|
|
|
console.log('ComPDFKitRN splitDocumentPages:', splitResult);
|
|
|
if (splitResult) {
|
|
|
- console.log('ComPDFKitRN splitDocumentPages: Split document saved at:', savePath);
|
|
|
- await pdfReaderRef?.current?._pdfDocument.open(savePath);
|
|
|
+ console.log('ComPDFKitRN splitDocumentPages: Split document saved at:', uniqueFilePath);
|
|
|
+ await pdfReaderRef?.current?._pdfDocument.open(uniqueFilePath);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -137,8 +140,10 @@ const CPDFPagesExampleScreen = () => {
|
|
|
onImport={async (document, pageRange, insertPosition) => {
|
|
|
setImportModalVisible(false);
|
|
|
const importResult = await pdfReaderRef.current?._pdfDocument.importDocument(
|
|
|
- document, pageRange, insertPosition
|
|
|
- )
|
|
|
+ document, pageRange, insertPosition,
|
|
|
+ ).catch((error) => {
|
|
|
+ console.log('ComPDFKitRN importDocument:', error.message);
|
|
|
+ });
|
|
|
console.log('ComPDFKitRN importDocument:', importResult);
|
|
|
}} />
|
|
|
</View>
|