Selaa lähdekoodia

compdfkit(RN) - 编辑模式保存失败问题

yangliuhua 3 kuukautta sitten
vanhempi
commit
217a6b0c2b
2 muutettua tiedostoa jossa 23 lisäystä ja 5 poistoa
  1. 8 2
      example/src/CPDFReaderViewExample.tsx
  2. 15 3
      ios/RCTCPDFView.swift

+ 8 - 2
example/src/CPDFReaderViewExample.tsx

@@ -9,7 +9,7 @@
 
 import React, { useState, useEffect, useRef } from 'react';
 import { Platform } from 'react-native';
-import { CPDFReaderView, ComPDFKit } from '@compdfkit_pdf_sdk/react_native';
+import { CPDFReaderView, ComPDFKit,CPDFToolbarAction } from '@compdfkit_pdf_sdk/react_native';
 import { useNavigation, useRoute, RouteProp } from '@react-navigation/native';
 
 type RootStackParamList = {
@@ -62,7 +62,13 @@ const CPDFReaderViewExampleScreen = () => {
         <CPDFReaderView
             ref={pdfReaderRef}
             document={samplePDF}
-            configuration={ComPDFKit.getDefaultConfig({})}
+            configuration={ComPDFKit.getDefaultConfig({
+                toolbarConfig: {
+                    iosLeftBarAvailableActions:[
+                        CPDFToolbarAction.THUMBNAIL
+                      ]
+                }
+            })}
         />
     );
 };

+ 15 - 3
ios/RCTCPDFView.swift

@@ -66,9 +66,21 @@ class RCTCPDFView: UIView {
     // MARK: - Public Methods
     
     func saveDocument(completionHandler: @escaping (Bool) -> Void) {
-        let document = self.pdfViewController?.pdfListView?.document
-        let success = document?.write(to: document?.documentURL ?? URL(fileURLWithPath: ""), isSaveFontSubset: true) ?? false
-        completionHandler(success)
+        if (self.pdfViewController?.pdfListView?.isEditing() == true && self.pdfViewController?.pdfListView?.isEdited() == true) {
+            self.pdfViewController?.pdfListView?.commitEditing()
+            
+            if self.pdfViewController?.pdfListView?.document.isModified() == true {
+                let document = self.pdfViewController?.pdfListView?.document
+                let success = document?.write(to: document?.documentURL ?? URL(fileURLWithPath: ""), isSaveFontSubset: true) ?? false
+                completionHandler(success)
+            }
+        } else {
+            if self.pdfViewController?.pdfListView?.document.isModified() == true {
+                let document = self.pdfViewController?.pdfListView?.document
+                let success = document?.write(to: document?.documentURL ?? URL(fileURLWithPath: ""), isSaveFontSubset: true) ?? false
+                completionHandler(success)
+            }
+        }
     }
     
     // MARK: - RCT Methods