Explorar o código

compdfkit(rn) - v2.3.0-beta.1 新增导入导出表单接口

liuxiaolong hai 1 semana
pai
achega
bccc0953ba

+ 46 - 0
API.md

@@ -246,6 +246,30 @@ ComPDFKit.setImportFontDir('fontdir', true);
 ComPDFKit.init_('your license key');
 ```
 
+### createUri
+
+This method is supported only on the Android platform. It is used to create a URI for saving a file on the Android device.
+The file is saved in the `Downloads` directory by default, but you can specify a subdirectory within `Downloads` using the [childDirectoryName] parameter. If the [childDirectoryName] is not provided, the file will be saved directly in the `Downloads` directory.
+The [fileName] parameter is required to specify the name of the file (e.g., `test.pdf`).
+
+Parameters:
+
+| Name               | Type   | Description                                                 |
+| ------------------ | ------ | ----------------------------------------------------------- |
+| fileName           | string | specifies the name of the file, for example `test.pdf`.     |
+| childDirectoryName | string | specifies a subdirectory within the `Downloads` folder.     |
+| mimeType           | string | the MIME type of the file, defaulting to `application/pdf`. |
+
+Returns a Promise.
+
+| Name | Type   | Description                           |
+| ---- | ------ | ------------------------------------- |
+| uri  | string | Returns the uri used to save the file |
+
+```tsx
+const uri: string = await ComPDFKit.createUri('test.pdf', '', 'application/pdf');
+```
+
 ## CPDFReaderView - Props
 
 ### Open Document
@@ -423,6 +447,20 @@ Returns a Promise.
 const isImageDoc = await pdfReaderRef.current?._pdfDocument.isImageDoc();
 ```
 
+#### getDocumentPath
+
+Retrieves the path of the current document.
+
+Returns a Promise.
+
+| Name | Type   | Description                                 |
+| ---- | ------ | ------------------------------------------- |
+| path | string | Retrieves the path of the current document. |
+
+```tsx
+const documentPath = await pdfReaderRef.current?._pdfDocument.getDocumentPath();
+```
+
 ### Viewer
 
 #### setMargins
@@ -879,6 +917,14 @@ Enters snip mode, allowing users to capture screenshots.
 await pdfReaderRef.current?.exitSnipMode();
 ```
 
+#### printDocument
+
+Invokes the system's print service to print the current document.
+
+```tsx
+await pdfReaderRef.current?._pdfDocument.printDocument();
+```
+
 ### Page
 
 #### setDisplayPageIndex

+ 10 - 3
CHANGELOG.md

@@ -1,16 +1,23 @@
 ## Newest Release
+
 ### 2.3.0-beta.1 - 28 Feb. 2025
+
 * Added import/export interface for form data in XFDF format files.
+* Added the ability to create text input boxes and insert images by clicking on the page area in content editing mode.
+* Added a system print API for navigation.
 * Fixed issue where editing or deleting text in some documents caused crashes.
 * Fixed issue with the border appearing after completing FreeText annotation.
 * Fixed issue where the LaBan Key input method deletes the last character when editing text.
 
+* Fixed the issue of text garbling in content editing mode.
+
+
+
 ## Previous Release
 
 ### 2.2.2 - 19 Feb. 2025
 
 * Added the features support for ComPDFKit PDF SDK for iOS iOS V2.2.2.
-
 * Added the features support for ComPDFKit PDF SDK for Android Android V2.2.2.
 * Added the ability to save a watermark to the current PDF when adding it.
 * Fixed the inaccurate judgment issue in the `hasChange()` method.
@@ -22,6 +29,7 @@
 * Fixed a crash issue on the Android platform when importing XFDF annotations.
 
 ### 2.2.1 - 21 Jan. 2025
+
 * Added the features support for ComPDFKit PDF SDK for iOS [iOS V2.2.1](https://www.compdf.com/pdf-sdk/changelog-ios#v2-2-1).
 * Added the features support for ComPDFKit PDF SDK for Android [Android V2.2.1](https://www.compdf.com/pdf-sdk/changelog-android#v2-2-1).
 * Added API for importing fonts.
@@ -42,8 +50,8 @@
 * Fixed an issue on Android where cloud comment borders were displayed incorrectly in graphic annotations.
   For detailed information about the new interfaces, please refer to `CPDFReaderView.tsx` and `CPDFDocument.tsx`.
 
-
 ### 2.2.0 - 13 Dec. 2024
+
 * Added features support for ComPDFKit PDF SDK for [Android V2.2.0](https://www.compdf.com/pdf-sdk/changelog-android#v2-2-0).
 * Added features support for ComPDFKit PDF SDK for [iOS V2.2.0](https://www.compdf.com/pdf-sdk/changelog-ios#v2-2-0).
 * Added import and export annotation interfaces.
@@ -93,7 +101,6 @@
 * Android platform adaptation for **Laban Key Keyboard**.
 * Fixed an issue with the Ink annotation color display on Android.
 
-
 ### 2.0.1 - 13 May 2024
 
 * Provide dependency methods from GitHub and npm.

+ 4 - 4
README.md

@@ -115,8 +115,8 @@ open ios/Podfile
 ```diff
 target 'MyApp' do
     # ...
-+    pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.2.podspec'
-+  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.2.podspec'
++    pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.3.0-beta.podspec'
++  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.3.0-beta.podspec'
     # ...
 end
 ```
@@ -126,8 +126,8 @@ end
 ```diff
 target 'MyApp' do
     # ...
-+  pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.2'
-+  pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.2.2'
++  pod 'ComPDFKit', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.3.0-beta'
++  pod 'ComPDFKit_Tools', :git => 'https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift.git', :tag => '2.3.0-beta'
     # ...
 end
 ```

+ 2 - 1
android/build.gradle

@@ -78,7 +78,8 @@ repositories {
 
   mavenCentral()
   google()
-  mavenLocal()
+  maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
+
 }
 
 

+ 2 - 3
example/android/build.gradle

@@ -10,8 +10,6 @@ buildscript {
   repositories {
     google()
     mavenCentral()
-    mavenLocal()
-
   }
   dependencies {
     classpath("com.android.tools.build:gradle")
@@ -24,7 +22,8 @@ allprojects {
   repositories {
     google()
     mavenCentral()
-    mavenLocal()
+    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
+
   }
 }
 

+ 2 - 2
example/android/config.gradle

@@ -6,7 +6,7 @@ ext {
             VERSIONCODE: 1011
     ]
     sdk = [
-            COMPDFKIT_SDK_VERSION : "2.2.0",
-            COMPDFKIT_SDK_BUILD_TAG : "build_dev_2.2.0_4aef7ae8_202412101057"
+            COMPDFKIT_SDK_VERSION : "2.3.0-beta.1",
+            COMPDFKIT_SDK_BUILD_TAG : "build_dev_2.3.0_4aef7ae8_202502281000"
     ]
 }

+ 2 - 2
example/ios/CompdfkitPdfExample.xcodeproj/project.pbxproj

@@ -510,7 +510,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 2.3.0;
+				MARKETING_VERSION = "2.3.0-beta";
 				ONLY_ACTIVE_ARCH = YES;
 				OTHER_LDFLAGS = (
 					"$(inherited)",
@@ -547,7 +547,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 2.3.0;
+				MARKETING_VERSION = "2.3.0-beta";
 				ONLY_ACTIVE_ARCH = YES;
 				OTHER_LDFLAGS = (
 					"$(inherited)",

+ 2 - 2
example/ios/Podfile

@@ -16,8 +16,8 @@ end
 
 target 'CompdfkitPdfExample' do
   config = use_native_modules!
-  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.2.podspec'
-  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.2.podspec'
+  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.3.0-beta.podspec'
+  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.3.0-beta.podspec'
 
 
   use_react_native!(

+ 10 - 11
example/src/CPDFReaderViewControllerExample.tsx

@@ -75,7 +75,6 @@ const CPDFReaderViewControllerExampleScreen = () => {
     const menuOptions = [
         'openDocument',
         'save',
-        'saveAs',
         'hasChange',
         'DisplaySettings',
         'PreviewModeScreen',
@@ -108,17 +107,17 @@ const CPDFReaderViewControllerExampleScreen = () => {
             case 'save':
                 handleSave();
                 break;
-            case 'saveAs':
-                const appCacheDirectory = RNFS.CachesDirectoryPath;
-                const savePath = appCacheDirectory + '/save_as_test.pdf';
+            // case 'saveAs':
+            //     const appCacheDirectory = RNFS.CachesDirectoryPath;
+            //     const savePath = appCacheDirectory + '/save_as_test.pdf';
 
-                // const androidUri = await ComPDFKit.createUri('save_as_test.pdf', '', 'application/pdf');
-                const success = await pdfReaderRef.current?._pdfDocument.saveAs(savePath, false, true);
-                if(success){
-                    await pdfReaderRef.current?._pdfDocument.open(savePath, '');
-                }
-                console.log('ComPDFKitRN saveAs:', success);
-                break;
+            //     // const androidUri = await ComPDFKit.createUri('save_as_test.pdf', '', 'application/pdf');
+            //     const success = await pdfReaderRef.current?._pdfDocument.saveAs(savePath, false, true);
+            //     if(success){
+            //         await pdfReaderRef.current?._pdfDocument.open(savePath, '');
+            //     }
+            //     console.log('ComPDFKitRN saveAs:', success);
+            //     break;
             case 'hasChange':
                 const hasChange = await pdfReaderRef.current?._pdfDocument.hasChange();
                 console.log('ComPDFKitRN hasChange:', hasChange);

+ 12 - 13
example/src/CPDFSecurityExample.tsx

@@ -43,7 +43,6 @@ const CPDFSecurityExampleScreen = () => {
         'Set Password',
         'Remove Password',
         'Check Owner Password',
-        'flatten All Pages',
         'Document Info'];
 
     const handleMenuItemPress = async (action: string) => {
@@ -60,21 +59,21 @@ const CPDFSecurityExampleScreen = () => {
             case 'Check Owner Password':
                 console.log('ComPDFKit-RN checkOwnerPassword:', await document?.checkOwnerPassword('4321'));
                 break;
-            case 'flatten All Pages':
+            // case 'flatten All Pages':
 
-                const appCacheDirectory = RNFS.CachesDirectoryPath;
-                const savePath = appCacheDirectory + '/flattened.pdf';
+            //     const appCacheDirectory = RNFS.CachesDirectoryPath;
+            //     const savePath = appCacheDirectory + '/flattened.pdf';
 
-                // only android platform
-                // const savePath = await ComPDFKit.createUri('rn_flatten_test.pdf', 'compdfkit', 'application/pdf');
+            //     // only android platform
+            //     // const savePath = await ComPDFKit.createUri('rn_flatten_test.pdf', 'compdfkit', 'application/pdf');
 
-                const flattenResult = await document?.flattenAllPages(savePath, true)
-                .catch(error => {
-                    console.log('ComPDFKit-RN flattenAllPages error:', error);
-                });
-                await pdfReaderRef.current?.reloadPages();
-                console.log('ComPDFKit-RN flattenAllPages:', flattenResult);
-                break;
+            //     const flattenResult = await document?.flattenAllPages(savePath, true)
+            //     .catch(error => {
+            //         console.log('ComPDFKit-RN flattenAllPages error:', error);
+            //     });
+            //     await pdfReaderRef.current?.reloadPages();
+            //     console.log('ComPDFKit-RN flattenAllPages:', flattenResult);
+            //     break;
             case 'Document Info':
                 console.log('ComPDFKit-RN fileName:', await document?.getFileName());
                 console.log('ComPDFKit-RN documentPath:', await document?.getDocumentPath());

+ 2 - 2
src/index.tsx

@@ -168,13 +168,13 @@ declare module 'react-native' {
        * The [fileName] parameter is required to specify the name of the file (e.g., `test.pdf`).
        *
        * @example
-       * const uri: string | null = await ComPDFKit.createUri('test.pdf');
+       * const uri: string = await ComPDFKit.createUri('test.pdf', '', 'application/pdf');
        *
        * @param { string } fileName(required): specifies the name of the file, for example `test.pdf`.
        * @param { string } childDirectoryName (optional): specifies a subdirectory within the `Downloads` folder.
        * @param { string } mimeType (optional): the MIME type of the file, defaulting to `application/pdf`.
        */
-      createUri : (fileName : string, childDIrectoryName : string | null, mimeType : string) => Promise<string>;
+      createUri : (fileName : string, childDirectoryName : string | null, mimeType : string) => Promise<string>;
     };
   }
 }

+ 35 - 27
src/view/CPDFDocument.tsx

@@ -347,7 +347,7 @@ export class CPDFDocument {
         if (tag != null) {
             return CPDFViewManager.exportWidgets(tag);
         }
-        return Promise.reject('Unable to find the native view reference');
+        return Promise.reject(new Error('Unable to find the native view reference'));
     }
 
     /**
@@ -361,7 +361,7 @@ export class CPDFDocument {
         if (tag != null) {
             return CPDFViewManager.printDocument(tag);
         }
-        return Promise.reject('Unable to find the native view reference');
+        return Promise.reject(new Error('Unable to find the native view reference'));
     }
 
     /**
@@ -376,16 +376,16 @@ export class CPDFDocument {
      * const result = await pdfReaderRef.current?._pdfDocument.flattenAllPages(savePath, fontSubset);
      * @returns Returns the save path of the current document.
      */
-    flattenAllPages = (savePath : string, fontSubset : boolean) : Promise<string> => {
-        const tag = findNodeHandle(this._viewerRef);
-        if (tag != null) {
-            return CPDFViewManager.flattenAllPages(tag, {
-                'save_path': savePath,
-                'font_sub_set': fontSubset
-            });
-        }
-        return Promise.reject('Unable to find the native view reference');
-    }
+    // flattenAllPages = (savePath : string, fontSubset : boolean) : Promise<string> => {
+    //     const tag = findNodeHandle(this._viewerRef);
+    //     if (tag != null) {
+    //         return CPDFViewManager.flattenAllPages(tag, {
+    //             'save_path': savePath,
+    //             'font_sub_set': fontSubset
+    //         });
+    //     }
+    //     return Promise.reject(new Error('Unable to find the native view reference'));
+    // }
 
     /**
      * Saves the document to the specified directory.
@@ -403,31 +403,39 @@ export class CPDFDocument {
      * @param fontSubset
      * @returns Whether to embed the font subset when saving the PDF.
      */
-    saveAs = (savePath : string, removeSecurity : boolean, fontSubset : boolean) : Promise<string> => {
-        const tag = findNodeHandle(this._viewerRef);
-        if (tag != null) {
-            return CPDFViewManager.saveAs(tag, {
-                'save_path': savePath,
-                'remove_security': removeSecurity,
-                'font_sub_set': fontSubset
-            });
-        }
-        return Promise.reject('Unable to find the native view reference');
-    }
+    // saveAs = (savePath : string, removeSecurity : boolean, fontSubset : boolean) : Promise<string> => {
+    //     const tag = findNodeHandle(this._viewerRef);
+    //     if (tag != null) {
+    //         return CPDFViewManager.saveAs(tag, {
+    //             'save_path': savePath,
+    //             'remove_security': removeSecurity,
+    //             'font_sub_set': fontSubset
+    //         });
+    //     }
+    //     return Promise.reject(new Error('Unable to find the native view reference'));
+    // }
 
     /**
-     * 返回当前文档的路径。
-     * 在安卓平台,如果通过uri打开的文档,会返回uri
+     * Retrieves the path of the current document.
+     * On Android, if the document was opened via a URI, the URI will be returned.
+     * 
+     * This function returns the path of the document being viewed. If the document was opened 
+     * through a file URI on Android, the URI string will be returned instead of a file path.
+     * 
      * @example
      * const documentPath = await pdfReaderRef.current?._pdfDocument.getDocumentPath();
-     * @returns The path of the current document.
+     * 
+     * @returns A promise that resolves to the path (or URI) of the current document.
+     * If the native view reference is not found, the promise will be rejected with an error.
+     * 
+     * @throws Will reject with an error message if the native view reference cannot be found.
      */
     getDocumentPath = () : Promise<string> => {
         const tag = findNodeHandle(this._viewerRef);
         if (tag != null) {
             return CPDFViewManager.getDocumentPath(tag);
         }
-        return Promise.reject('Unable to find the native view reference');
+        return Promise.reject(new Error('Unable to find the native view reference'));
     }
 
 }