@mmgodc/capacitor-plugin-pdftron 0.0.1 → 0.0.2

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/Package.swift CHANGED
@@ -7,17 +7,22 @@ let package = Package(
7
7
  products: [
8
8
  .library(
9
9
  name: "CapacitorPluginPdftron",
10
+ targets: ["PDFTronPlugin"]),
11
+ .library(
12
+ name: "MmgodcCapacitorPluginPdftron",
10
13
  targets: ["PDFTronPlugin"])
11
14
  ],
12
15
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
16
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0"),
17
+ .package(url: "https://github.com/PDFTron/pdftron-apple-package", from: "11.0.0")
14
18
  ],
15
19
  targets: [
16
20
  .target(
17
21
  name: "PDFTronPlugin",
18
22
  dependencies: [
19
23
  .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
- .product(name: "Cordova", package: "capacitor-swift-pm")
24
+ .product(name: "Cordova", package: "capacitor-swift-pm"),
25
+ .product(name: "PDFTron", package: "pdftron-apple-package")
21
26
  ],
22
27
  path: "ios/Sources/PDFTronPlugin"),
23
28
  .testTarget(
@@ -25,4 +30,4 @@ let package = Package(
25
30
  dependencies: ["PDFTronPlugin"],
26
31
  path: "ios/Tests/PDFTronPluginTests")
27
32
  ]
28
- )
33
+ )
package/README.md CHANGED
@@ -16,6 +16,7 @@ npx cap sync
16
16
  * [`echo(...)`](#echo)
17
17
  * [`initialize(...)`](#initialize)
18
18
  * [`saveDocument()`](#savedocument)
19
+ * [`close()`](#close)
19
20
 
20
21
  </docgen-index>
21
22
 
@@ -53,7 +54,18 @@ initialize(options: { settings: string; viewerElement: string; }) => Promise<voi
53
54
  ### saveDocument()
54
55
 
55
56
  ```typescript
56
- saveDocument() => Promise<void>
57
+ saveDocument() => Promise<{ filePath: string; }>
58
+ ```
59
+
60
+ **Returns:** <code>Promise&lt;{ filePath: string; }&gt;</code>
61
+
62
+ --------------------
63
+
64
+
65
+ ### close()
66
+
67
+ ```typescript
68
+ close() => Promise<void>
57
69
  ```
58
70
 
59
71
  --------------------
@@ -1,71 +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
- }
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
+ }
@@ -1,102 +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
- }
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
102
  }
@@ -365,4 +365,21 @@ public class PDFTronPlugin extends Plugin {
365
365
  }
366
366
 
367
367
  // 对外方法-关闭
368
+ @PluginMethod
369
+ public void close(PluginCall call) {
370
+
371
+ if (mDocumentView != null) {
372
+ if (mDocumentView.mPdfViewCtrlTabHostFragment != null && mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment() != null) {
373
+ mDocumentView.mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().onDestroy();
374
+
375
+ }
376
+ Activity activity = getActivity();
377
+ if (activity!=null&&!activity.isFinishing()){
378
+ activity.runOnUiThread(() -> mDocumentView.onNavButtonPressed());
379
+ }
380
+ }
381
+
382
+ JSObject ret = new JSObject();
383
+ call.resolve(ret);
384
+ }
368
385
  }
package/dist/docs.json CHANGED
@@ -39,13 +39,23 @@
39
39
  },
40
40
  {
41
41
  "name": "saveDocument",
42
+ "signature": "() => Promise<{ filePath: string; }>",
43
+ "parameters": [],
44
+ "returns": "Promise<{ filePath: string; }>",
45
+ "tags": [],
46
+ "docs": "",
47
+ "complexTypes": [],
48
+ "slug": "savedocument"
49
+ },
50
+ {
51
+ "name": "close",
42
52
  "signature": "() => Promise<void>",
43
53
  "parameters": [],
44
54
  "returns": "Promise<void>",
45
55
  "tags": [],
46
56
  "docs": "",
47
57
  "complexTypes": [],
48
- "slug": "savedocument"
58
+ "slug": "close"
49
59
  }
50
60
  ],
51
61
  "properties": []
@@ -8,5 +8,8 @@ export interface PDFTronPlugin {
8
8
  settings: string;
9
9
  viewerElement: string;
10
10
  }): Promise<void>;
11
- saveDocument(): Promise<void>;
11
+ saveDocument(): Promise<{
12
+ filePath: string;
13
+ }>;
14
+ close(): Promise<void>;
12
15
  }
@@ -1 +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"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface PDFTronPlugin {\n // 基本方法\n echo(options: { value: string }): Promise<{ value: string }>;\n\n // 初始化\n initialize(options: { settings: string; viewerElement: string }): Promise<void>;\n \n // 保存\n saveDocument(): Promise<{ filePath: string }>;\n\n // 关闭\n close(): Promise<void>;\n}\n"]}
@@ -1 +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"]}
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';\n\nimport type { PDFTronPlugin } from './definitions';\n\nconst PDFTron = registerPlugin<PDFTronPlugin>('PDFTron', {\n web: () => import('./web').then((m) => new m.PDFTronWeb()),\n});\n\nexport * from './definitions';\nexport { PDFTron };\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -10,5 +10,8 @@ export declare class PDFTronWeb extends WebPlugin implements PDFTronPlugin {
10
10
  settings: string;
11
11
  viewerElement: string;
12
12
  }): Promise<void>;
13
- saveDocument(): Promise<void>;
13
+ saveDocument(): Promise<{
14
+ filePath: string;
15
+ }>;
16
+ close(): Promise<void>;
14
17
  }
package/dist/esm/web.js CHANGED
@@ -10,6 +10,10 @@ export class PDFTronWeb extends WebPlugin {
10
10
  console.log('web options', options);
11
11
  }
12
12
  // 保存
13
- async saveDocument() { }
13
+ async saveDocument() {
14
+ return { filePath: '' };
15
+ }
16
+ // 关闭
17
+ async close() { }
14
18
  }
15
19
  //# sourceMappingURL=web.js.map
@@ -1 +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"]}
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;QAChB,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK;IACL,KAAK,CAAC,KAAK,KAAmB,CAAC;CAChC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { PDFTronPlugin } from './definitions';\n\nexport class PDFTronWeb extends WebPlugin implements PDFTronPlugin {\n // 基本方法\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n\n // 初始化\n async initialize(options: { settings: string; viewerElement: string }): Promise<void> {\n console.log('web options', options);\n }\n\n // 保存\n async saveDocument(): Promise<{ filePath: string }> {\n return { filePath: '' };\n }\n\n // 关闭\n async close(): Promise<void> {}\n}\n"]}
@@ -17,7 +17,11 @@ class PDFTronWeb extends core.WebPlugin {
17
17
  console.log('web options', options);
18
18
  }
19
19
  // 保存
20
- async saveDocument() { }
20
+ async saveDocument() {
21
+ return { filePath: '' };
22
+ }
23
+ // 关闭
24
+ async close() { }
21
25
  }
22
26
 
23
27
  var web = /*#__PURE__*/Object.freeze({
@@ -1 +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;;;;;;;;;"}
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 return { filePath: '' };\n }\n // 关闭\n async close() { }\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;AACzB,QAAQ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;AAC/B,IAAI;AACJ;AACA,IAAI,MAAM,KAAK,GAAG,EAAE;AACpB;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -16,7 +16,11 @@ var capacitorPDFTron = (function (exports, core) {
16
16
  console.log('web options', options);
17
17
  }
18
18
  // 保存
19
- async saveDocument() { }
19
+ async saveDocument() {
20
+ return { filePath: '' };
21
+ }
22
+ // 关闭
23
+ async close() { }
20
24
  }
21
25
 
22
26
  var web = /*#__PURE__*/Object.freeze({
@@ -1 +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;;;;;;;;;;;;;;;"}
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 return { filePath: '' };\n }\n // 关闭\n async close() { }\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;IACzB,QAAQ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC/B,IAAI;IACJ;IACA,IAAI,MAAM,KAAK,GAAG,EAAE;IACpB;;;;;;;;;;;;;;;"}
@@ -1,23 +1,221 @@
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
- }
1
+ import Foundation
2
+ import Capacitor
3
+ import UIKit
4
+ import PDFNet
5
+ import Tools
6
+
7
+ @objc(PDFTronPlugin)
8
+ public class PDFTronPlugin: CAPPlugin, CAPBridgedPlugin {
9
+ public let identifier = "PDFTronPlugin"
10
+ public let jsName = "PDFTron"
11
+ public let pluginMethods: [CAPPluginMethod] = [
12
+ CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
13
+ CAPPluginMethod(name: "initialize", returnType: CAPPluginReturnPromise),
14
+ CAPPluginMethod(name: "saveDocument", returnType: CAPPluginReturnPromise),
15
+ CAPPluginMethod(name: "close", returnType: CAPPluginReturnPromise)
16
+ ]
17
+
18
+ private static var pdfNetInitialized = false
19
+
20
+ private let implementation = PDFTron()
21
+ private var documentController: PTDocumentController?
22
+ private var navigationController: UINavigationController?
23
+ private var currentDocumentURL: URL?
24
+
25
+ @objc func echo(_ call: CAPPluginCall) {
26
+ let value = call.getString("value") ?? ""
27
+ call.resolve([
28
+ "value": implementation.echo(value)
29
+ ])
30
+ }
31
+
32
+ @objc func initialize(_ call: CAPPluginCall) {
33
+ let settingsString = call.getString("settings") ?? "{}"
34
+ _ = call.getString("viewerElement") ?? ""
35
+
36
+ guard let data = settingsString.data(using: .utf8) else {
37
+ call.reject("Invalid settings")
38
+ return
39
+ }
40
+
41
+ var rect = UIScreen.main.bounds
42
+ var initialDocURL: URL?
43
+ var password: String?
44
+ var disabledElements: [String] = []
45
+
46
+ do {
47
+ if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] {
48
+ if let rectString = json["boundingRect"] as? String,
49
+ let rectData = rectString.data(using: .utf8),
50
+ let rectObject = try JSONSerialization.jsonObject(with: rectData) as? [String: Any] {
51
+ let left = (rectObject["left"] as? Double) ?? 0
52
+ let top = (rectObject["top"] as? Double) ?? 0
53
+ let width = (rectObject["width"] as? Double) ?? 0
54
+ let height = (rectObject["height"] as? Double) ?? 0
55
+ rect = CGRect(x: left, y: top, width: width, height: height)
56
+ }
57
+
58
+ if let initialDoc = json["initialDoc"] as? String, !initialDoc.isEmpty {
59
+ initialDocURL = url(from: initialDoc)
60
+ }
61
+
62
+ if let pwd = json["password"] as? String, !pwd.isEmpty {
63
+ password = pwd
64
+ }
65
+
66
+ if let disabled = json["disabledElements"] as? [Any] {
67
+ for value in disabled {
68
+ if let name = value as? String {
69
+ disabledElements.append(name)
70
+ }
71
+ }
72
+ }
73
+ }
74
+ } catch {
75
+ call.reject("Invalid settings")
76
+ return
77
+ }
78
+
79
+ DispatchQueue.main.async {
80
+ if !PDFTronPlugin.pdfNetInitialized {
81
+ PTPDFNet.initialize("demo")
82
+ PDFTronPlugin.pdfNetInitialized = true
83
+ }
84
+
85
+ guard let rootViewController = self.bridge?.viewController else {
86
+ call.reject("No root view controller")
87
+ return
88
+ }
89
+
90
+ if let existingNav = self.navigationController {
91
+ existingNav.view.removeFromSuperview()
92
+ existingNav.removeFromParent()
93
+ self.navigationController = nil
94
+ self.documentController = nil
95
+ }
96
+
97
+ let documentController = PTDocumentController()
98
+ self.documentController = documentController
99
+
100
+ self.applyDisabledElements(disabledElements, to: documentController)
101
+
102
+ if let url = initialDocURL {
103
+ if let pwd = password {
104
+ documentController.openDocument(with: url, password: pwd)
105
+ } else {
106
+ documentController.openDocument(with: url)
107
+ }
108
+ self.currentDocumentURL = url
109
+ } else {
110
+ self.currentDocumentURL = nil
111
+ }
112
+
113
+ let navController = UINavigationController(rootViewController: documentController)
114
+ navController.modalPresentationStyle = .fullScreen
115
+ navController.navigationBar.isTranslucent = false
116
+ navController.toolbar.isTranslucent = false
117
+ navController.view.frame = rect
118
+
119
+ rootViewController.addChild(navController)
120
+ rootViewController.view.addSubview(navController.view)
121
+ navController.didMove(toParent: rootViewController)
122
+
123
+ self.navigationController = navController
124
+
125
+ call.resolve()
126
+ }
127
+ }
128
+
129
+ @objc func saveDocument(_ call: CAPPluginCall) {
130
+ DispatchQueue.main.async {
131
+ guard let controller = self.documentController else {
132
+ call.reject("No document is open")
133
+ return
134
+ }
135
+
136
+ let options = PTSaveOptions(rawValue: 0)
137
+ controller.saveDocument(options) { success in
138
+ if success {
139
+ let url = self.currentDocumentURL
140
+ var path = ""
141
+ if let url = url {
142
+ path = url.isFileURL ? url.path : url.absoluteString
143
+ }
144
+ call.resolve([
145
+ "filePath": path
146
+ ])
147
+ } else {
148
+ call.reject("Save failed")
149
+ }
150
+ }
151
+ }
152
+ }
153
+
154
+ @objc func close(_ call: CAPPluginCall) {
155
+ DispatchQueue.main.async {
156
+ if let navController = self.navigationController {
157
+ navController.view.removeFromSuperview()
158
+ navController.removeFromParent()
159
+ self.navigationController = nil
160
+ self.documentController = nil
161
+ }
162
+ call.resolve()
163
+ }
164
+ }
165
+
166
+ private func applyDisabledElements(_ items: [String], to controller: PTDocumentController) {
167
+ if items.isEmpty {
168
+ return
169
+ }
170
+
171
+ if items.contains("toolsButton") {
172
+ controller.areToolGroupsEnabled = false
173
+ controller.setToolGroupToolbarHidden(true, animated: false)
174
+ }
175
+
176
+ if items.contains("searchButton") {
177
+ let searchItem = controller.searchButtonItem
178
+ var rightItems = controller.navigationItem.rightBarButtonItems ?? []
179
+ rightItems.removeAll { $0 == searchItem }
180
+ controller.navigationItem.rightBarButtonItems = rightItems
181
+ }
182
+
183
+ if items.contains("thumbnailsButton") {
184
+ let thumbnailsItem = controller.thumbnailsButtonItem
185
+ var rightItems = controller.navigationItem.rightBarButtonItems ?? []
186
+ rightItems.removeAll { $0 == thumbnailsItem }
187
+ controller.navigationItem.rightBarButtonItems = rightItems
188
+ }
189
+
190
+ if items.contains("listsButton") {
191
+ let listsItem = controller.navigationListsButtonItem
192
+ var rightItems = controller.navigationItem.rightBarButtonItems ?? []
193
+ rightItems.removeAll { $0 == listsItem }
194
+ controller.navigationItem.rightBarButtonItems = rightItems
195
+ }
196
+
197
+ if items.contains("shareButton") {
198
+ controller.isShareButtonHidden = true
199
+ }
200
+
201
+ if items.contains("viewControlsButton") {
202
+ controller.isViewerSettingsButtonHidden = true
203
+ }
204
+
205
+ if items.contains("thumbnailSlider") {
206
+ controller.thumbnailSliderController.view.isHidden = true
207
+ }
208
+ }
209
+
210
+ private func url(from string: String) -> URL? {
211
+ if string.hasPrefix("http://") || string.hasPrefix("https://") {
212
+ return URL(string: string)
213
+ }
214
+ if string.hasPrefix("file://") {
215
+ if let url = URL(string: string) {
216
+ return URL(fileURLWithPath: url.path)
217
+ }
218
+ }
219
+ return URL(fileURLWithPath: string)
220
+ }
221
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmgodc/capacitor-plugin-pdftron",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "PDFTron mobile SDK for Capacitor.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,13 +0,0 @@
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>