@mmgodc/capacitor-plugin-pdftron 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorPluginPdftron.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +61 -0
- package/android/build.gradle +71 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/mmg/plugins/pdftron/DocumentView.java +102 -0
- package/android/src/main/java/com/mmg/plugins/pdftron/PDFTronPlugin.java +368 -0
- package/android/src/main/main.iml +13 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +57 -0
- package/dist/esm/definitions.d.ts +12 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +14 -0
- package/dist/esm/web.js +15 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +29 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +32 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/PDFTronPlugin/PDFTron.swift +8 -0
- package/ios/Sources/PDFTronPlugin/PDFTronPlugin.swift +23 -0
- package/ios/Tests/PDFTronPluginTests/pdftronPluginTests.swift +15 -0
- package/package.json +81 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorPluginPdftron'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapacitorPluginPdftron",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapacitorPluginPdftron",
|
|
10
|
+
targets: ["PDFTronPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "PDFTronPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/PDFTronPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "PDFTronPluginTests",
|
|
25
|
+
dependencies: ["PDFTronPlugin"],
|
|
26
|
+
path: "ios/Tests/PDFTronPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# capacitor-plugin-pdftron
|
|
2
|
+
|
|
3
|
+
PDFTron mobile SDK for Capacitor.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install capacitor-plugin-pdftron
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
<docgen-index>
|
|
15
|
+
|
|
16
|
+
* [`echo(...)`](#echo)
|
|
17
|
+
* [`initialize(...)`](#initialize)
|
|
18
|
+
* [`saveDocument()`](#savedocument)
|
|
19
|
+
|
|
20
|
+
</docgen-index>
|
|
21
|
+
|
|
22
|
+
<docgen-api>
|
|
23
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
24
|
+
|
|
25
|
+
### echo(...)
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
echo(options: { value: string; }) => Promise<{ value: string; }>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Param | Type |
|
|
32
|
+
| ------------- | ------------------------------- |
|
|
33
|
+
| **`options`** | <code>{ value: string; }</code> |
|
|
34
|
+
|
|
35
|
+
**Returns:** <code>Promise<{ value: string; }></code>
|
|
36
|
+
|
|
37
|
+
--------------------
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### initialize(...)
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
initialize(options: { settings: string; viewerElement: string; }) => Promise<void>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Param | Type |
|
|
47
|
+
| ------------- | --------------------------------------------------------- |
|
|
48
|
+
| **`options`** | <code>{ settings: string; viewerElement: string; }</code> |
|
|
49
|
+
|
|
50
|
+
--------------------
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### saveDocument()
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
saveDocument() => Promise<void>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
--------------------
|
|
60
|
+
|
|
61
|
+
</docgen-api>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.mmg.plugins.pdftron"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
|
|
30
|
+
// PDFTron相关信息
|
|
31
|
+
multiDexEnabled true
|
|
32
|
+
vectorDrawables.useSupportLibrary = true
|
|
33
|
+
manifestPlaceholders = [pdftronLicenseKey:""]
|
|
34
|
+
}
|
|
35
|
+
buildTypes {
|
|
36
|
+
release {
|
|
37
|
+
minifyEnabled false
|
|
38
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
lintOptions {
|
|
42
|
+
abortOnError false
|
|
43
|
+
}
|
|
44
|
+
compileOptions {
|
|
45
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
46
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
repositories {
|
|
51
|
+
google()
|
|
52
|
+
mavenCentral()
|
|
53
|
+
maven {
|
|
54
|
+
url "https://pdftron-maven.s3.amazonaws.com/release"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
dependencies {
|
|
60
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
61
|
+
implementation project(':capacitor-android')
|
|
62
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
63
|
+
testImplementation "junit:junit:$junitVersion"
|
|
64
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
65
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
66
|
+
|
|
67
|
+
// PDFTron相关依赖
|
|
68
|
+
implementation "com.pdftron:pdftron:11.9.0"
|
|
69
|
+
implementation "com.pdftron:tools:11.9.0"
|
|
70
|
+
|
|
71
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<application>
|
|
3
|
+
<!-- Add license key in meta-data tag here. This should be inside the application tag. -->
|
|
4
|
+
<meta-data android:name="pdftron_license_key" android:value="${pdftronLicenseKey}"/>
|
|
5
|
+
</application>
|
|
6
|
+
</manifest>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
package com.mmg.plugins.pdftron;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.util.AttributeSet;
|
|
5
|
+
import android.view.ViewGroup;
|
|
6
|
+
|
|
7
|
+
import androidx.annotation.NonNull;
|
|
8
|
+
import androidx.annotation.Nullable;
|
|
9
|
+
|
|
10
|
+
public class DocumentView extends com.pdftron.pdf.controls.DocumentView {
|
|
11
|
+
|
|
12
|
+
private int left;
|
|
13
|
+
private int top;
|
|
14
|
+
private int width;
|
|
15
|
+
private int height;
|
|
16
|
+
|
|
17
|
+
private boolean useCustomRect;
|
|
18
|
+
private String resTitle;
|
|
19
|
+
|
|
20
|
+
private PDFTronPlugin myPlugin;
|
|
21
|
+
|
|
22
|
+
public DocumentView(@NonNull Context context) {
|
|
23
|
+
super(context);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public DocumentView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
27
|
+
super(context, attrs);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public DocumentView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
31
|
+
super(context, attrs, defStyleAttr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
public void setNavIconResName(String resName) {
|
|
36
|
+
resTitle = resName;
|
|
37
|
+
super.setNavIconResName(resName);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public void setPlugin(PDFTronPlugin pdftron) {
|
|
41
|
+
myPlugin = pdftron;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public void setRect(int l, int t, int w, int h) {
|
|
45
|
+
useCustomRect = true;
|
|
46
|
+
this.left = l;
|
|
47
|
+
this.top = t;
|
|
48
|
+
this.width = w;
|
|
49
|
+
this.height = h;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public boolean isUseCustomRect() {
|
|
53
|
+
return useCustomRect;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Override
|
|
57
|
+
public void onNavButtonPressed() {
|
|
58
|
+
boolean handled = false;
|
|
59
|
+
if (resTitle != null && myPlugin != null) {
|
|
60
|
+
if (resTitle.equals("ic_arrow_back_white_24dp") || resTitle.equals("ic_close_white_24dp")) {
|
|
61
|
+
if (getParent() instanceof ViewGroup) {
|
|
62
|
+
myPlugin.hideView();
|
|
63
|
+
handled = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!handled) {
|
|
68
|
+
sendJavascriptEvent("topLeftButtonPressed");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Override
|
|
73
|
+
public void onTabDocumentLoaded(String tag) {
|
|
74
|
+
sendJavascriptEvent("documentLoaded");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private void sendJavascriptEvent(String event) {
|
|
78
|
+
if (myPlugin == null) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
myPlugin.fireJavascriptEvent(event);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
86
|
+
if (useCustomRect) {
|
|
87
|
+
int nextWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
|
|
88
|
+
int nextHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
|
89
|
+
super.onMeasure(nextWidthMeasureSpec, nextHeightMeasureSpec);
|
|
90
|
+
|
|
91
|
+
layout(left, top, left + width, top + height);
|
|
92
|
+
|
|
93
|
+
if (getLayoutParams() != null && getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
|
|
94
|
+
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) getLayoutParams();
|
|
95
|
+
params.leftMargin = left;
|
|
96
|
+
params.topMargin = top;
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
package com.mmg.plugins.pdftron;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.net.Uri;
|
|
5
|
+
import android.os.Bundle;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
import android.view.View;
|
|
8
|
+
import android.view.ViewGroup;
|
|
9
|
+
import android.webkit.WebView;
|
|
10
|
+
|
|
11
|
+
import com.getcapacitor.JSObject;
|
|
12
|
+
import com.getcapacitor.Logger;
|
|
13
|
+
import com.getcapacitor.Plugin;
|
|
14
|
+
import com.getcapacitor.PluginCall;
|
|
15
|
+
import com.getcapacitor.PluginMethod;
|
|
16
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
17
|
+
|
|
18
|
+
import com.pdftron.common.PDFNetException;
|
|
19
|
+
import com.pdftron.pdf.PDFViewCtrl;
|
|
20
|
+
import com.pdftron.pdf.config.ToolManagerBuilder;
|
|
21
|
+
import com.pdftron.pdf.config.ViewerConfig;
|
|
22
|
+
import com.pdftron.pdf.controls.PdfViewCtrlTabFragment;
|
|
23
|
+
import com.pdftron.pdf.tools.ToolManager;
|
|
24
|
+
import com.pdftron.pdf.utils.Utils;
|
|
25
|
+
|
|
26
|
+
import org.json.JSONArray;
|
|
27
|
+
import org.json.JSONException;
|
|
28
|
+
import org.json.JSONObject;
|
|
29
|
+
|
|
30
|
+
import java.util.ArrayList;
|
|
31
|
+
|
|
32
|
+
import androidx.annotation.NonNull;
|
|
33
|
+
import androidx.annotation.Nullable;
|
|
34
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
35
|
+
|
|
36
|
+
@CapacitorPlugin(name = "PDFTron")
|
|
37
|
+
public class PDFTronPlugin extends Plugin {
|
|
38
|
+
|
|
39
|
+
private static final String TAG = "PDFTron";
|
|
40
|
+
|
|
41
|
+
// options
|
|
42
|
+
public static final String Key_initialDoc = "initialDoc";
|
|
43
|
+
public static final String Key_password = "password";
|
|
44
|
+
public static final String Key_boundingRect = "boundingRect";
|
|
45
|
+
public static final String Key_disabledElements = "disabledElements";
|
|
46
|
+
public static final String Key_showNavIcon = "showTopLeftButton";
|
|
47
|
+
public static final String Key_navIconTitle = "topLeftButtonTitle";
|
|
48
|
+
|
|
49
|
+
// methods
|
|
50
|
+
public static final String Key_showDocumentViewer = "showDocumentViewer";
|
|
51
|
+
public static final String Key_disableElements = "disableElements";
|
|
52
|
+
public static final String Key_enableTools = "enableTools";
|
|
53
|
+
public static final String Key_disableTools = "disableTools";
|
|
54
|
+
public static final String Key_setToolMode = "setToolMode";
|
|
55
|
+
public static final String Key_setPagePresentationMode = "setPagePresentationMode";
|
|
56
|
+
public static final String Key_loadDocument = "loadDocument";
|
|
57
|
+
public static final String Key_save = "save";
|
|
58
|
+
public static final String Key_NativeViewer = "NativeViewer";
|
|
59
|
+
|
|
60
|
+
// nav
|
|
61
|
+
public static final String Key_close = "close";
|
|
62
|
+
public static final String Key_menu = "menu";
|
|
63
|
+
public static final String Key_back = "back";
|
|
64
|
+
|
|
65
|
+
private DocumentView mDocumentView;
|
|
66
|
+
private ViewerConfig.Builder mBuilder;
|
|
67
|
+
private ToolManagerBuilder mToolManagerBuilder;
|
|
68
|
+
|
|
69
|
+
// 对外方法-基本方法(示例)
|
|
70
|
+
@PluginMethod
|
|
71
|
+
public void echo(PluginCall call) {
|
|
72
|
+
String value = call.getString("value");
|
|
73
|
+
|
|
74
|
+
JSObject ret = new JSObject();
|
|
75
|
+
Logger.info("Echo", value);
|
|
76
|
+
ret.put("value", value);
|
|
77
|
+
call.resolve(ret);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 对外方法-初始化
|
|
81
|
+
@PluginMethod
|
|
82
|
+
public void initialize(PluginCall call) {
|
|
83
|
+
mBuilder = new ViewerConfig.Builder()
|
|
84
|
+
.useSupportActionBar(false)
|
|
85
|
+
.fullscreenModeEnabled(false)
|
|
86
|
+
.multiTabEnabled(false)
|
|
87
|
+
.saveCopyExportPath(getContext().getCacheDir().getAbsolutePath())
|
|
88
|
+
.openUrlCachePath(getContext().getCacheDir().getAbsolutePath());
|
|
89
|
+
mToolManagerBuilder = ToolManagerBuilder.from();
|
|
90
|
+
|
|
91
|
+
// 获取配置
|
|
92
|
+
String options = call.getString("settings");
|
|
93
|
+
// 获取加载组件
|
|
94
|
+
String viewerElement = call.getString("viewerElement");
|
|
95
|
+
// 创建Viewer
|
|
96
|
+
addDocumentViewer(options, viewerElement, call);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 添加文档视图
|
|
100
|
+
private void addDocumentViewer(String options, String viewerElement, PluginCall call) {
|
|
101
|
+
try {
|
|
102
|
+
final JSONObject jsonObject = new JSONObject(options);
|
|
103
|
+
getActivity().runOnUiThread(() -> createDocumentViewerImpl(jsonObject, viewerElement, call));
|
|
104
|
+
} catch (Exception e) {
|
|
105
|
+
e.printStackTrace();
|
|
106
|
+
call.reject(e.getMessage());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 创建文档视图实例
|
|
111
|
+
private void createDocumentViewerImpl(@NonNull JSONObject options, @Nullable String viewerElement, PluginCall call) {
|
|
112
|
+
try {
|
|
113
|
+
Activity currentActivity = getActivity();
|
|
114
|
+
if (currentActivity instanceof AppCompatActivity) {
|
|
115
|
+
AppCompatActivity fragmentActivity = (AppCompatActivity) getActivity();
|
|
116
|
+
|
|
117
|
+
mDocumentView = new DocumentView(getContext());
|
|
118
|
+
mDocumentView.setSupportFragmentManager(fragmentActivity.getSupportFragmentManager());
|
|
119
|
+
mDocumentView.setPlugin(this);
|
|
120
|
+
|
|
121
|
+
// 配置-初始文档
|
|
122
|
+
if (options.has(Key_initialDoc)) {
|
|
123
|
+
String initialDoc = options.getString(Key_initialDoc);
|
|
124
|
+
mDocumentView.setDocumentUri(Uri.parse(initialDoc));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (options.has(Key_password)) {
|
|
128
|
+
String password = options.getString(Key_password);
|
|
129
|
+
mDocumentView.setPassword(password);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 配置-渲染位置
|
|
133
|
+
if (options.has(Key_boundingRect)) {
|
|
134
|
+
String rect = options.getString(Key_boundingRect);
|
|
135
|
+
Log.d("capacitor", "boundingRect: " + rect);
|
|
136
|
+
JSONObject rectObject = new JSONObject(rect);
|
|
137
|
+
int left = (int) Float.parseFloat(rectObject.getString("left"));
|
|
138
|
+
int top = (int) Float.parseFloat(rectObject.getString("top"));
|
|
139
|
+
int width = (int) Float.parseFloat(rectObject.getString("width"));
|
|
140
|
+
int height = (int) Float.parseFloat(rectObject.getString("height"));
|
|
141
|
+
mDocumentView.setRect((int) Utils.convDp2Pix(getContext(), left),
|
|
142
|
+
(int) Utils.convDp2Pix(getContext(), top),
|
|
143
|
+
(int) Utils.convDp2Pix(getContext(), width),
|
|
144
|
+
(int) Utils.convDp2Pix(getContext(), height));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 配置-禁用组件
|
|
148
|
+
if (options.has(Key_disabledElements)) {
|
|
149
|
+
disableElements(options.getJSONArray(Key_disabledElements));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 配置-左上角按钮
|
|
153
|
+
String navIcon = "ic_menu_white_24dp";
|
|
154
|
+
if (options.has(Key_navIconTitle)) {
|
|
155
|
+
String title = options.getString(Key_navIconTitle);
|
|
156
|
+
if (Key_menu.equalsIgnoreCase(title)) {
|
|
157
|
+
navIcon = "ic_menu_white_24dp";
|
|
158
|
+
} else if (Key_back.equalsIgnoreCase(title)) {
|
|
159
|
+
navIcon = "ic_arrow_back_white_24dp";
|
|
160
|
+
} else if (Key_close.equalsIgnoreCase(title)) {
|
|
161
|
+
navIcon = "ic_close_white_24dp";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
mDocumentView.setNavIconResName(navIcon);
|
|
165
|
+
boolean showNav = true;
|
|
166
|
+
// 是否展示左上角按钮
|
|
167
|
+
if (options.has(Key_showNavIcon)) {
|
|
168
|
+
showNav = options.getBoolean(Key_showNavIcon);
|
|
169
|
+
}
|
|
170
|
+
mDocumentView.setShowNavIcon(showNav);
|
|
171
|
+
|
|
172
|
+
if (!Utils.isNullOrEmpty(viewerElement)) {
|
|
173
|
+
attachDocumentViewerImpl();
|
|
174
|
+
}
|
|
175
|
+
call.resolve();
|
|
176
|
+
} else {
|
|
177
|
+
call.reject("Current activity is not instanceof FragmentActivity");
|
|
178
|
+
}
|
|
179
|
+
} catch (Exception e) {
|
|
180
|
+
e.printStackTrace();
|
|
181
|
+
call.reject(e.getMessage());
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 隐藏组件
|
|
186
|
+
private void disableElements(JSONArray args) throws JSONException {
|
|
187
|
+
for (int i = 0; i < args.length(); i++) {
|
|
188
|
+
String item = args.getString(i);
|
|
189
|
+
if ("toolsButton".equals(item)) {
|
|
190
|
+
mBuilder = mBuilder.showAnnotationToolbarOption(false);
|
|
191
|
+
} else if ("searchButton".equals(item)) {
|
|
192
|
+
mBuilder = mBuilder.showSearchView(false);
|
|
193
|
+
} else if ("shareButton".equals(item)) {
|
|
194
|
+
mBuilder = mBuilder.showShareOption(false);
|
|
195
|
+
} else if ("viewControlsButton".equals(item)) {
|
|
196
|
+
mBuilder = mBuilder.showDocumentSettingsOption(false);
|
|
197
|
+
} else if ("thumbnailsButton".equals(item)) {
|
|
198
|
+
mBuilder = mBuilder.showThumbnailView(false);
|
|
199
|
+
} else if ("listsButton".equals(item)) {
|
|
200
|
+
mBuilder = mBuilder
|
|
201
|
+
.showAnnotationsList(false)
|
|
202
|
+
.showOutlineList(false)
|
|
203
|
+
.showUserBookmarksList(false);
|
|
204
|
+
} else if ("thumbnailSlider".equals(item)) {
|
|
205
|
+
mBuilder = mBuilder.showBottomNavBar(false);
|
|
206
|
+
} else if ("editPagesButton".equals(item)) {
|
|
207
|
+
mBuilder = mBuilder.showEditPagesOption(false);
|
|
208
|
+
} else if ("printButton".equals(item)) {
|
|
209
|
+
mBuilder = mBuilder.showPrintOption(false);
|
|
210
|
+
} else if ("closeButton".equals(item)) {
|
|
211
|
+
mBuilder = mBuilder.showCloseTabOption(false);
|
|
212
|
+
} else if ("saveCopyButton".equals(item)) {
|
|
213
|
+
mBuilder = mBuilder.showSaveCopyOption(false);
|
|
214
|
+
} else if ("formToolsButton".equals(item)) {
|
|
215
|
+
mBuilder = mBuilder.showFormToolbarOption(false);
|
|
216
|
+
} else if ("moreItemsButton".equals(item)) {
|
|
217
|
+
mBuilder = mBuilder
|
|
218
|
+
.showEditPagesOption(false)
|
|
219
|
+
.showPrintOption(false)
|
|
220
|
+
.showCloseTabOption(false)
|
|
221
|
+
.showSaveCopyOption(false)
|
|
222
|
+
.showFormToolbarOption(false);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
disableTools(args);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 隐藏工具栏
|
|
229
|
+
private void disableTools(JSONArray args) throws JSONException {
|
|
230
|
+
ArrayList<ToolManager.ToolMode> modesArr = new ArrayList<>();
|
|
231
|
+
for (int i = 0; i < args.length(); i++) {
|
|
232
|
+
String item = args.getString(i);
|
|
233
|
+
ToolManager.ToolMode mode = convStringToToolMode(item);
|
|
234
|
+
if (mode != null) {
|
|
235
|
+
modesArr.add(mode);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
ToolManager.ToolMode[] modes = modesArr.toArray(new ToolManager.ToolMode[modesArr.size()]);
|
|
239
|
+
if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
|
|
240
|
+
ToolManager toolManager = mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getToolManager();
|
|
241
|
+
if (toolManager != null) {
|
|
242
|
+
toolManager.disableToolMode(modes);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
mToolManagerBuilder = mToolManagerBuilder.disableToolModes(modes);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 工具栏类型转换
|
|
250
|
+
private ToolManager.ToolMode convStringToToolMode(String item) {
|
|
251
|
+
ToolManager.ToolMode mode = null;
|
|
252
|
+
if ("freeHandToolButton".equals(item) || "AnnotationCreateFreeHand".equals(item)) {
|
|
253
|
+
mode = ToolManager.ToolMode.INK_CREATE;
|
|
254
|
+
} else if ("highlightToolButton".equals(item) || "AnnotationCreateTextHighlight".equals(item)) {
|
|
255
|
+
mode = ToolManager.ToolMode.TEXT_HIGHLIGHT;
|
|
256
|
+
} else if ("underlineToolButton".equals(item) || "AnnotationCreateTextUnderline".equals(item)) {
|
|
257
|
+
mode = ToolManager.ToolMode.TEXT_UNDERLINE;
|
|
258
|
+
} else if ("squigglyToolButton".equals(item) || "AnnotationCreateTextSquiggly".equals(item)) {
|
|
259
|
+
mode = ToolManager.ToolMode.TEXT_SQUIGGLY;
|
|
260
|
+
} else if ("strikeoutToolButton".equals(item) || "AnnotationCreateTextStrikeout".equals(item)) {
|
|
261
|
+
mode = ToolManager.ToolMode.TEXT_STRIKEOUT;
|
|
262
|
+
} else if ("rectangleToolButton".equals(item) || "AnnotationCreateRectangle".equals(item)) {
|
|
263
|
+
mode = ToolManager.ToolMode.RECT_CREATE;
|
|
264
|
+
} else if ("ellipseToolButton".equals(item) || "AnnotationCreateEllipse".equals(item)) {
|
|
265
|
+
mode = ToolManager.ToolMode.OVAL_CREATE;
|
|
266
|
+
} else if ("lineToolButton".equals(item) || "AnnotationCreateLine".equals(item)) {
|
|
267
|
+
mode = ToolManager.ToolMode.LINE_CREATE;
|
|
268
|
+
} else if ("arrowToolButton".equals(item) || "AnnotationCreateArrow".equals(item)) {
|
|
269
|
+
mode = ToolManager.ToolMode.ARROW_CREATE;
|
|
270
|
+
} else if ("polylineToolButton".equals(item) || "AnnotationCreatePolyline".equals(item)) {
|
|
271
|
+
mode = ToolManager.ToolMode.POLYLINE_CREATE;
|
|
272
|
+
} else if ("polygonToolButton".equals(item) || "AnnotationCreatePolygon".equals(item)) {
|
|
273
|
+
mode = ToolManager.ToolMode.POLYGON_CREATE;
|
|
274
|
+
} else if ("cloudToolButton".equals(item) || "AnnotationCreatePolygonCloud".equals(item)) {
|
|
275
|
+
mode = ToolManager.ToolMode.CLOUD_CREATE;
|
|
276
|
+
} else if ("signatureToolButton".equals(item) || "AnnotationCreateSignature".equals(item)) {
|
|
277
|
+
mode = ToolManager.ToolMode.SIGNATURE;
|
|
278
|
+
} else if ("freeTextToolButton".equals(item) || "AnnotationCreateFreeText".equals(item)) {
|
|
279
|
+
mode = ToolManager.ToolMode.TEXT_CREATE;
|
|
280
|
+
} else if ("stickyToolButton".equals(item) || "AnnotationCreateSticky".equals(item)) {
|
|
281
|
+
mode = ToolManager.ToolMode.TEXT_ANNOT_CREATE;
|
|
282
|
+
} else if ("calloutToolButton".equals(item) || "AnnotationCreateCallout".equals(item)) {
|
|
283
|
+
mode = ToolManager.ToolMode.CALLOUT_CREATE;
|
|
284
|
+
} else if ("stampToolButton".equals(item) || "AnnotationCreateStamp".equals(item)) {
|
|
285
|
+
mode = ToolManager.ToolMode.STAMPER;
|
|
286
|
+
} else if ("AnnotationCreateDistanceMeasurement".equals(item)) {
|
|
287
|
+
mode = ToolManager.ToolMode.RULER_CREATE;
|
|
288
|
+
} else if ("AnnotationCreatePerimeterMeasurement".equals(item)) {
|
|
289
|
+
mode = ToolManager.ToolMode.PERIMETER_MEASURE_CREATE;
|
|
290
|
+
} else if ("AnnotationCreateAreaMeasurement".equals(item)) {
|
|
291
|
+
mode = ToolManager.ToolMode.AREA_MEASURE_CREATE;
|
|
292
|
+
} else if ("TextSelect".equals(item)) {
|
|
293
|
+
mode = ToolManager.ToolMode.TEXT_SELECT;
|
|
294
|
+
} else if ("AnnotationEdit".equals(item)) {
|
|
295
|
+
mode = ToolManager.ToolMode.ANNOT_EDIT_RECT_GROUP;
|
|
296
|
+
}
|
|
297
|
+
return mode;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 添加文档视图实例
|
|
301
|
+
private void attachDocumentViewerImpl() throws PDFNetException {
|
|
302
|
+
if (mDocumentView == null) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
mDocumentView.setVisibility(View.VISIBLE);
|
|
306
|
+
if (mDocumentView.getParent() != null) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
mDocumentView.setViewerConfig(getViewerConfig());
|
|
310
|
+
if (bridge.getWebView() instanceof WebView) {
|
|
311
|
+
WebView wv = (WebView) bridge.getWebView();
|
|
312
|
+
if (wv.getParent() != null && wv.getParent() instanceof ViewGroup) {
|
|
313
|
+
((ViewGroup) wv.getParent()).addView(mDocumentView);
|
|
314
|
+
} else {
|
|
315
|
+
wv.addView(mDocumentView);
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
throw new PDFNetException("CapacitorWebView is not instanceof WebView", -1, "PDFTron.java", "attachDocumentViewerImpl", "Unable to add viewer.");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// 获取ToolManager设置
|
|
323
|
+
private ViewerConfig getViewerConfig() {
|
|
324
|
+
return mBuilder
|
|
325
|
+
.toolManagerBuilder(mToolManagerBuilder)
|
|
326
|
+
.build();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 隐藏视图
|
|
330
|
+
public void hideView() {
|
|
331
|
+
if (mDocumentView == null) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
mDocumentView.setVisibility(View.GONE);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 接收监听信息
|
|
338
|
+
public void fireJavascriptEvent(String action) {
|
|
339
|
+
sendEventMessage(action);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 发送监听消息给JS端
|
|
343
|
+
private void sendEventMessage(String action) {
|
|
344
|
+
JSONObject obj = new JSONObject();
|
|
345
|
+
try {
|
|
346
|
+
obj.put("action", action);
|
|
347
|
+
} catch (JSONException e) {
|
|
348
|
+
Log.e(TAG, "Failed to create event message", e);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// 对外方法-保存
|
|
353
|
+
@PluginMethod
|
|
354
|
+
public void saveDocument(PluginCall call) {
|
|
355
|
+
if (mDocumentView != null && mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
|
|
356
|
+
mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().save(false, true, true);
|
|
357
|
+
|
|
358
|
+
JSObject ret = new JSObject();
|
|
359
|
+
ret.put("filePath", mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getFilePath());
|
|
360
|
+
|
|
361
|
+
call.resolve(ret);
|
|
362
|
+
} else {
|
|
363
|
+
call.reject("Saving failed.");
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// 对外方法-关闭
|
|
368
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$">
|
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
|
|
7
|
+
</content>
|
|
8
|
+
<orderEntry type="inheritedJdk" />
|
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
10
|
+
<orderEntry type="module" module-name="test" />
|
|
11
|
+
<orderEntry type="module" module-name="test" />
|
|
12
|
+
</component>
|
|
13
|
+
</module>
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "PDFTronPlugin",
|
|
4
|
+
"slug": "pdftronplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "echo",
|
|
10
|
+
"signature": "(options: { value: string; }) => Promise<{ value: string; }>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "{ value: string; }"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<{ value: string; }>",
|
|
19
|
+
"tags": [],
|
|
20
|
+
"docs": "",
|
|
21
|
+
"complexTypes": [],
|
|
22
|
+
"slug": "echo"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "initialize",
|
|
26
|
+
"signature": "(options: { settings: string; viewerElement: string; }) => Promise<void>",
|
|
27
|
+
"parameters": [
|
|
28
|
+
{
|
|
29
|
+
"name": "options",
|
|
30
|
+
"docs": "",
|
|
31
|
+
"type": "{ settings: string; viewerElement: string; }"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"returns": "Promise<void>",
|
|
35
|
+
"tags": [],
|
|
36
|
+
"docs": "",
|
|
37
|
+
"complexTypes": [],
|
|
38
|
+
"slug": "initialize"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "saveDocument",
|
|
42
|
+
"signature": "() => Promise<void>",
|
|
43
|
+
"parameters": [],
|
|
44
|
+
"returns": "Promise<void>",
|
|
45
|
+
"tags": [],
|
|
46
|
+
"docs": "",
|
|
47
|
+
"complexTypes": [],
|
|
48
|
+
"slug": "savedocument"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"properties": []
|
|
52
|
+
},
|
|
53
|
+
"interfaces": [],
|
|
54
|
+
"enums": [],
|
|
55
|
+
"typeAliases": [],
|
|
56
|
+
"pluginConfigs": []
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface PDFTronPlugin {\r\n // 基本方法\r\n echo(options: { value: string }): Promise<{ value: string }>;\r\n\r\n // 初始化\r\n initialize(options: { settings: string; viewerElement: string }): Promise<void>;\r\n \r\n // 保存\r\n saveDocument(): Promise<void>;\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,OAAO,GAAG,cAAc,CAAgB,SAAS,EAAE;IACvD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;CAC3D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\r\n\r\nimport type { PDFTronPlugin } from './definitions';\r\n\r\nconst PDFTron = registerPlugin<PDFTronPlugin>('PDFTron', {\r\n web: () => import('./web').then((m) => new m.PDFTronWeb()),\r\n});\r\n\r\nexport * from './definitions';\r\nexport { PDFTron };\r\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PDFTronPlugin } from './definitions';
|
|
3
|
+
export declare class PDFTronWeb extends WebPlugin implements PDFTronPlugin {
|
|
4
|
+
echo(options: {
|
|
5
|
+
value: string;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
value: string;
|
|
8
|
+
}>;
|
|
9
|
+
initialize(options: {
|
|
10
|
+
settings: string;
|
|
11
|
+
viewerElement: string;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
saveDocument(): Promise<void>;
|
|
14
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class PDFTronWeb extends WebPlugin {
|
|
3
|
+
// 基本方法
|
|
4
|
+
async echo(options) {
|
|
5
|
+
console.log('ECHO', options);
|
|
6
|
+
return options;
|
|
7
|
+
}
|
|
8
|
+
// 初始化
|
|
9
|
+
async initialize(options) {
|
|
10
|
+
console.log('web options', options);
|
|
11
|
+
}
|
|
12
|
+
// 保存
|
|
13
|
+
async saveDocument() { }
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvC,OAAO;IACP,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM;IACN,KAAK,CAAC,UAAU,CAAC,OAAoD;QACnE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,KAAK;IACL,KAAK,CAAC,YAAY,KAAmB,CAAC;CACvC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\r\n\r\nimport type { PDFTronPlugin } from './definitions';\r\n\r\nexport class PDFTronWeb extends WebPlugin implements PDFTronPlugin {\r\n // 基本方法\r\n async echo(options: { value: string }): Promise<{ value: string }> {\r\n console.log('ECHO', options);\r\n return options;\r\n }\r\n\r\n // 初始化\r\n async initialize(options: { settings: string; viewerElement: string }): Promise<void> {\r\n console.log('web options', options);\r\n }\r\n\r\n // 保存\r\n async saveDocument(): Promise<void> {}\r\n}\r\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const PDFTron = core.registerPlugin('PDFTron', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PDFTronWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class PDFTronWeb extends core.WebPlugin {
|
|
10
|
+
// 基本方法
|
|
11
|
+
async echo(options) {
|
|
12
|
+
console.log('ECHO', options);
|
|
13
|
+
return options;
|
|
14
|
+
}
|
|
15
|
+
// 初始化
|
|
16
|
+
async initialize(options) {
|
|
17
|
+
console.log('web options', options);
|
|
18
|
+
}
|
|
19
|
+
// 保存
|
|
20
|
+
async saveDocument() { }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
24
|
+
__proto__: null,
|
|
25
|
+
PDFTronWeb: PDFTronWeb
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
exports.PDFTron = PDFTron;
|
|
29
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PDFTron = registerPlugin('PDFTron', {\n web: () => import('./web').then((m) => new m.PDFTronWeb()),\n});\nexport * from './definitions';\nexport { PDFTron };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PDFTronWeb extends WebPlugin {\n // 基本方法\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n // 初始化\n async initialize(options) {\n console.log('web options', options);\n }\n // 保存\n async saveDocument() { }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS,EAAE;AAC1C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;AAC9D,CAAC;;ACFM,MAAM,UAAU,SAASC,cAAS,CAAC;AAC1C;AACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC,QAAQ,OAAO,OAAO;AACtB,IAAI;AACJ;AACA,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;AAC9B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC;AAC3C,IAAI;AACJ;AACA,IAAI,MAAM,YAAY,GAAG,EAAE;AAC3B;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var capacitorPDFTron = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const PDFTron = core.registerPlugin('PDFTron', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PDFTronWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class PDFTronWeb extends core.WebPlugin {
|
|
9
|
+
// 基本方法
|
|
10
|
+
async echo(options) {
|
|
11
|
+
console.log('ECHO', options);
|
|
12
|
+
return options;
|
|
13
|
+
}
|
|
14
|
+
// 初始化
|
|
15
|
+
async initialize(options) {
|
|
16
|
+
console.log('web options', options);
|
|
17
|
+
}
|
|
18
|
+
// 保存
|
|
19
|
+
async saveDocument() { }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
23
|
+
__proto__: null,
|
|
24
|
+
PDFTronWeb: PDFTronWeb
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
exports.PDFTron = PDFTron;
|
|
28
|
+
|
|
29
|
+
return exports;
|
|
30
|
+
|
|
31
|
+
})({}, capacitorExports);
|
|
32
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst PDFTron = registerPlugin('PDFTron', {\n web: () => import('./web').then((m) => new m.PDFTronWeb()),\n});\nexport * from './definitions';\nexport { PDFTron };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PDFTronWeb extends WebPlugin {\n // 基本方法\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n // 初始化\n async initialize(options) {\n console.log('web options', options);\n }\n // 保存\n async saveDocument() { }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS,EAAE;IAC1C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;IAC9D,CAAC;;ICFM,MAAM,UAAU,SAASC,cAAS,CAAC;IAC1C;IACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC,QAAQ,OAAO,OAAO;IACtB,IAAI;IACJ;IACA,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;IAC9B,QAAQ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC;IAC3C,IAAI;IACJ;IACA,IAAI,MAAM,YAAY,GAAG,EAAE;IAC3B;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(PDFTronPlugin)
|
|
9
|
+
public class PDFTronPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
public let identifier = "PDFTronPlugin"
|
|
11
|
+
public let jsName = "PDFTron"
|
|
12
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
|
|
14
|
+
]
|
|
15
|
+
private let implementation = PDFTron()
|
|
16
|
+
|
|
17
|
+
@objc func echo(_ call: CAPPluginCall) {
|
|
18
|
+
let value = call.getString("value") ?? ""
|
|
19
|
+
call.resolve([
|
|
20
|
+
"value": implementation.echo(value)
|
|
21
|
+
])
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import PDFTronPlugin
|
|
3
|
+
|
|
4
|
+
class PDFTronTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = PDFTron()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mmgodc/capacitor-plugin-pdftron",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "PDFTron mobile SDK for Capacitor.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"CapacitorPluginPdftron.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://mmgdevops.visualstudio.com/Global%20Mobility/_git/capacitor-plugin-pdftron"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://mmgdevops.visualstudio.com/Global%20Mobility/_git/capacitor-plugin-pdftron/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
+
"verify:ios": "xcodebuild -scheme CapacitorPluginPdftron -destination generic/platform=iOS",
|
|
35
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
|
+
"verify:web": "npm run build",
|
|
37
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
|
+
"eslint": "eslint . --ext ts",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
41
|
+
"swiftlint": "node-swiftlint",
|
|
42
|
+
"docgen": "docgen --api PDFTronPlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
44
|
+
"clean": "rimraf ./dist",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"prepublishOnly": "npm run build",
|
|
47
|
+
"async": "npm run build && yalc push"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@capacitor/android": "^7.0.0",
|
|
51
|
+
"@capacitor/core": "^7.0.0",
|
|
52
|
+
"@capacitor/docgen": "^0.3.0",
|
|
53
|
+
"@capacitor/ios": "^7.0.0",
|
|
54
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
55
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
56
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"prettier": "^3.4.2",
|
|
59
|
+
"prettier-plugin-java": "^2.6.6",
|
|
60
|
+
"rimraf": "^6.1.2",
|
|
61
|
+
"rollup": "^4.30.1",
|
|
62
|
+
"swiftlint": "^2.0.0",
|
|
63
|
+
"typescript": "^5.9.3"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@capacitor/core": ">=7.0.0"
|
|
67
|
+
},
|
|
68
|
+
"prettier": "@ionic/prettier-config",
|
|
69
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
70
|
+
"eslintConfig": {
|
|
71
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
72
|
+
},
|
|
73
|
+
"capacitor": {
|
|
74
|
+
"ios": {
|
|
75
|
+
"src": "ios"
|
|
76
|
+
},
|
|
77
|
+
"android": {
|
|
78
|
+
"src": "android"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|