|
@@ -28,6 +28,7 @@ import androidx.fragment.app.FragmentActivity;
|
|
import com.compdfkit.core.common.CPDFDocumentException;
|
|
import com.compdfkit.core.common.CPDFDocumentException;
|
|
import com.compdfkit.core.document.CPDFDocument;
|
|
import com.compdfkit.core.document.CPDFDocument;
|
|
import com.compdfkit.core.document.CPDFDocument.PDFDocumentEncryptAlgo;
|
|
import com.compdfkit.core.document.CPDFDocument.PDFDocumentEncryptAlgo;
|
|
|
|
+import com.compdfkit.core.document.CPDFDocument.PDFDocumentError;
|
|
import com.compdfkit.core.document.CPDFDocument.PDFDocumentPermissions;
|
|
import com.compdfkit.core.document.CPDFDocument.PDFDocumentPermissions;
|
|
import com.compdfkit.core.document.CPDFDocument.PDFDocumentSaveType;
|
|
import com.compdfkit.core.document.CPDFDocument.PDFDocumentSaveType;
|
|
import com.compdfkit.core.document.CPDFDocumentPermissionInfo;
|
|
import com.compdfkit.core.document.CPDFDocumentPermissionInfo;
|
|
@@ -38,6 +39,7 @@ import com.compdfkit.tools.common.utils.CFileUtils;
|
|
import com.compdfkit.tools.common.utils.print.CPDFPrintUtils;
|
|
import com.compdfkit.tools.common.utils.print.CPDFPrintUtils;
|
|
import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
|
|
import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
|
|
import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
|
|
+import com.compdfkit.tools.common.views.pdfview.CPDFPageIndicatorView;
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl.COnSaveCallback;
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl.COnSaveCallback;
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl.COnSaveError;
|
|
import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl.COnSaveError;
|
|
@@ -47,12 +49,10 @@ import com.compdfkitpdf.reactnative.util.CPDFDocumentUtil;
|
|
import com.compdfkitpdf.reactnative.view.CPDFView;
|
|
import com.compdfkitpdf.reactnative.view.CPDFView;
|
|
import com.facebook.react.bridge.Promise;
|
|
import com.facebook.react.bridge.Promise;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
-import com.facebook.react.bridge.ReactMethod;
|
|
|
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
import com.facebook.react.uimanager.ViewGroupManager;
|
|
import com.facebook.react.uimanager.ViewGroupManager;
|
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
public class CPDFViewManager extends ViewGroupManager<CPDFView> {
|
|
public class CPDFViewManager extends ViewGroupManager<CPDFView> {
|
|
|
|
|
|
@@ -169,7 +169,7 @@ public class CPDFViewManager extends ViewGroupManager<CPDFView> {
|
|
}
|
|
}
|
|
|
|
|
|
public boolean importAnnotations(int tag, String xfdfFilePath) throws Exception {
|
|
public boolean importAnnotations(int tag, String xfdfFilePath) throws Exception {
|
|
- String xfdf = CPDFDocumentUtil.getImportAnnotationPath(reactContext, xfdfFilePath);
|
|
|
|
|
|
+ String xfdf = CPDFDocumentUtil.getImportFilePath(reactContext, xfdfFilePath);
|
|
CPDFView pdfView = mDocumentViews.get(tag);
|
|
CPDFView pdfView = mDocumentViews.get(tag);
|
|
CPDFReaderView readerView = pdfView.documentFragment.pdfView.getCPdfReaderView();
|
|
CPDFReaderView readerView = pdfView.documentFragment.pdfView.getCPdfReaderView();
|
|
CPDFDocument document = readerView.getPDFDocument();
|
|
CPDFDocument document = readerView.getPDFDocument();
|
|
@@ -466,7 +466,7 @@ public class CPDFViewManager extends ViewGroupManager<CPDFView> {
|
|
} else {
|
|
} else {
|
|
saveResult = document.saveAs(savePath, removeSecurity, false, fontSubSet);
|
|
saveResult = document.saveAs(savePath, removeSecurity, false, fontSubSet);
|
|
}
|
|
}
|
|
- CThreadPoolUtils.getInstance().executeMain(()->{
|
|
|
|
|
|
+ CThreadPoolUtils.getInstance().executeMain(() -> {
|
|
if (document.shouleReloadDocument()) {
|
|
if (document.shouleReloadDocument()) {
|
|
document.reload();
|
|
document.reload();
|
|
}
|
|
}
|
|
@@ -581,7 +581,7 @@ public class CPDFViewManager extends ViewGroupManager<CPDFView> {
|
|
}
|
|
}
|
|
|
|
|
|
public boolean importWidgets(int tag, String xfdfFilePath) throws Exception {
|
|
public boolean importWidgets(int tag, String xfdfFilePath) throws Exception {
|
|
- String xfdf = CPDFDocumentUtil.getImportAnnotationPath(reactContext, xfdfFilePath);
|
|
|
|
|
|
+ String xfdf = CPDFDocumentUtil.getImportFilePath(reactContext, xfdfFilePath);
|
|
CPDFView pdfView = mDocumentViews.get(tag);
|
|
CPDFView pdfView = mDocumentViews.get(tag);
|
|
CPDFReaderView readerView = pdfView.documentFragment.pdfView.getCPdfReaderView();
|
|
CPDFReaderView readerView = pdfView.documentFragment.pdfView.getCPdfReaderView();
|
|
CPDFDocument document = readerView.getPDFDocument();
|
|
CPDFDocument document = readerView.getPDFDocument();
|
|
@@ -649,19 +649,88 @@ public class CPDFViewManager extends ViewGroupManager<CPDFView> {
|
|
promise.reject("SAVE_FAIL", "Save failed.");
|
|
promise.reject("SAVE_FAIL", "Save failed.");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- if (e instanceof CPDFDocumentException){
|
|
|
|
|
|
+ if (e instanceof CPDFDocumentException) {
|
|
promise.reject("SAVE_FAIL", ((CPDFDocumentException) e).getErrType().name());
|
|
promise.reject("SAVE_FAIL", ((CPDFDocumentException) e).getErrType().name());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
promise.reject("SAVE_FAIL", e.getMessage());
|
|
promise.reject("SAVE_FAIL", e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void reloadPages(int tag){
|
|
|
|
|
|
+ public void reloadPages(int tag) {
|
|
CPDFView cpdfView = mDocumentViews.get(tag);
|
|
CPDFView cpdfView = mDocumentViews.get(tag);
|
|
cpdfView.getCPDFReaderView().reloadPages();
|
|
cpdfView.getCPDFReaderView().reloadPages();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void importDocument(int tag, String filePath, String password, int[] pages,
|
|
|
|
+ int insertPosition, Promise promise) {
|
|
|
|
+ try {
|
|
|
|
+ CPDFView cpdfView = mDocumentViews.get(tag);
|
|
|
|
+ CPDFDocument document = cpdfView.getCPDFReaderView().getPDFDocument();
|
|
|
|
+
|
|
|
|
+ CPDFDocument importDocument = new CPDFDocument(reactContext);
|
|
|
|
+ String importDocumentPath = CPDFDocumentUtil.getImportFilePath(reactContext, filePath);
|
|
|
|
+ PDFDocumentError error = importDocument.open(importDocumentPath, password);
|
|
|
|
+ if (error != PDFDocumentError.PDFDocumentErrorSuccess) {
|
|
|
|
+ promise.reject("IMPORT_DOCUMENT_FAIL", "open import document fail, error:" + error.name());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (pages == null || pages.length == 0) {
|
|
|
|
+ int pageCount = importDocument.getPageCount();
|
|
|
|
+ pages = new int[pageCount];
|
|
|
|
+ for (int i = 0; i < pageCount; i++) {
|
|
|
|
+ pages[i] = i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (insertPosition == -1) {
|
|
|
|
+ insertPosition = document.getPageCount();
|
|
|
|
+ }
|
|
|
|
+ boolean importResult = document.importPages(importDocument, pages, insertPosition);
|
|
|
|
+ promise.resolve(importResult);
|
|
|
|
+ CPDFPageIndicatorView indicatorView = cpdfView.documentFragment.pdfView.indicatorView;
|
|
|
|
+ cpdfView.getCPDFReaderView().reloadPages();
|
|
|
|
+ indicatorView.setTotalPage(document.getPageCount());
|
|
|
|
+ indicatorView.setCurrentPageIndex(cpdfView.getCPDFReaderView().getPageNum());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ promise.reject("IMPORT_DOCUMENT_FAIL", "error:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void splitDocumentPage(int tag, String savePath, int[] pages, Promise promise) {
|
|
|
|
+ try {
|
|
|
|
+ CPDFView cpdfView = mDocumentViews.get(tag);
|
|
|
|
+ CPDFDocument document = cpdfView.getCPDFReaderView().getPDFDocument();
|
|
|
|
+ if (pages == null || pages.length == 0) {
|
|
|
|
+ int pageCount = document.getPageCount();
|
|
|
|
+ pages = new int[pageCount];
|
|
|
|
+ for (int i = 0; i < pageCount; i++) {
|
|
|
|
+ pages[i] = i;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int[] finalPages = pages;
|
|
|
|
+ CThreadPoolUtils.getInstance().executeIO(() -> {
|
|
|
|
+ try {
|
|
|
|
+ CPDFDocument newDocument = CPDFDocument.createDocument(reactContext);
|
|
|
|
+ newDocument.importPages(document, finalPages, 0);
|
|
|
|
+ boolean saveResult;
|
|
|
|
+ if (savePath.startsWith(CONTENT_SCHEME)) {
|
|
|
|
+ saveResult = newDocument.saveAs(Uri.parse(savePath), false, true);
|
|
|
|
+ } else {
|
|
|
|
+ saveResult = newDocument.saveAs(savePath, false, false, true);
|
|
|
|
+ }
|
|
|
|
+ promise.resolve(saveResult);
|
|
|
|
+ newDocument.close();
|
|
|
|
+ } catch (CPDFDocumentException e) {
|
|
|
|
+ promise.reject("SPLIT_DOCUMENT_FAIL", "error:" + e.getErrType().name());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ promise.reject("SPLIT_DOCUMENT_FAIL", "error:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public String getDocumentPath(int tag) {
|
|
public String getDocumentPath(int tag) {
|
|
CPDFView pdfView = mDocumentViews.get(tag);
|
|
CPDFView pdfView = mDocumentViews.get(tag);
|
|
CPDFReaderView readerView = pdfView.getCPDFReaderView();
|
|
CPDFReaderView readerView = pdfView.getCPDFReaderView();
|