rn-pdf-king 1.2.0 → 1.3.0
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.
|
@@ -15,180 +15,188 @@ import kotlinx.coroutines.launch
|
|
|
15
15
|
import kotlinx.coroutines.withContext
|
|
16
16
|
|
|
17
17
|
class RnPdfKingModule : Module() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (uri != null) {
|
|
51
|
-
CoroutineScope(Dispatchers.Main).launch {
|
|
52
|
-
PdfKingManager.getInstance().handleUriSelection(uri)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
18
|
+
private val FILE_PICKER_REQUEST_CODE = 4242
|
|
19
|
+
|
|
20
|
+
override fun definition() = ModuleDefinition {
|
|
21
|
+
Name("RnPdfKing")
|
|
22
|
+
|
|
23
|
+
// Events
|
|
24
|
+
Events("onPdfLoadStarted", "onPdfLoadSuccess", "onPdfLoadError")
|
|
25
|
+
|
|
26
|
+
OnCreate {
|
|
27
|
+
val context = appContext.reactContext
|
|
28
|
+
if (context != null) {
|
|
29
|
+
PdfKingManager.initialize(context)
|
|
30
|
+
val pdfKing = PdfKingManager.getInstance()
|
|
31
|
+
pdfKing.onFileLoadStarted = {
|
|
32
|
+
this@RnPdfKingModule.sendEvent("onPdfLoadStarted", mapOf())
|
|
33
|
+
}
|
|
34
|
+
pdfKing.onFileLoadSuccess = { filePath, fileName, pageCount ->
|
|
35
|
+
this@RnPdfKingModule.sendEvent(
|
|
36
|
+
"onPdfLoadSuccess", mapOf(
|
|
37
|
+
"filePath" to filePath,
|
|
38
|
+
"fileName" to fileName,
|
|
39
|
+
"pageCount" to pageCount
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
pdfKing.onUnsupportedFile = {
|
|
44
|
+
this@RnPdfKingModule.sendEvent(
|
|
45
|
+
"onPdfLoadError",
|
|
46
|
+
mapOf("message" to "Unsupported or corrupt PDF file")
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
// Check for initial intent
|
|
52
|
+
appContext.currentActivity?.intent?.let { intent ->
|
|
53
|
+
if (intent.action == Intent.ACTION_VIEW) {
|
|
54
|
+
val uri = intent.data
|
|
55
|
+
if (uri != null) {
|
|
56
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
57
|
+
PdfKingManager.getInstance().handleUriSelection(uri)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
AsyncFunction("checkInitialIntent") {
|
|
71
|
-
appContext.currentActivity?.intent?.let { intent ->
|
|
63
|
+
|
|
64
|
+
OnNewIntent { intent ->
|
|
72
65
|
if (intent.action == Intent.ACTION_VIEW) {
|
|
73
66
|
val uri = intent.data
|
|
74
67
|
if (uri != null) {
|
|
75
68
|
CoroutineScope(Dispatchers.Main).launch {
|
|
76
69
|
PdfKingManager.getInstance().handleUriSelection(uri)
|
|
77
70
|
}
|
|
78
|
-
return@AsyncFunction true
|
|
79
71
|
}
|
|
80
72
|
}
|
|
81
73
|
}
|
|
82
|
-
return@AsyncFunction false
|
|
83
|
-
}
|
|
84
74
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
75
|
+
AsyncFunction("checkInitialIntent") {
|
|
76
|
+
appContext.currentActivity?.intent?.let { intent ->
|
|
77
|
+
if (intent.action == Intent.ACTION_VIEW) {
|
|
78
|
+
val uri = intent.data
|
|
79
|
+
if (uri != null) {
|
|
80
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
81
|
+
PdfKingManager.getInstance().handleUriSelection(uri)
|
|
82
|
+
}
|
|
83
|
+
return@AsyncFunction true
|
|
84
|
+
}
|
|
91
85
|
}
|
|
92
86
|
}
|
|
87
|
+
return@AsyncFunction false
|
|
93
88
|
}
|
|
94
|
-
}
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
val file = File(path)
|
|
106
|
-
if (file.exists()) {
|
|
107
|
-
CoroutineScope(Dispatchers.IO).launch {
|
|
108
|
-
try {
|
|
109
|
-
val pdfKing = PdfKingManager.getInstance()
|
|
110
|
-
withContext(Dispatchers.Main) {
|
|
111
|
-
pdfKing.onFileLoadStarted?.invoke()
|
|
112
|
-
}
|
|
113
|
-
pdfKing.loadPdf(file)
|
|
114
|
-
val count = pdfKing.getPageCountSync()
|
|
115
|
-
|
|
116
|
-
withContext(Dispatchers.Main) {
|
|
117
|
-
pdfKing.onFileLoadSuccess?.invoke(path, file.name, count)
|
|
118
|
-
}
|
|
119
|
-
} catch (e: Exception) {
|
|
120
|
-
this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to (e.message ?: "Unknown error")))
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to "File does not exist"))
|
|
90
|
+
OnActivityResult { _, payload ->
|
|
91
|
+
if (payload.requestCode == FILE_PICKER_REQUEST_CODE && payload.resultCode == Activity.RESULT_OK) {
|
|
92
|
+
val uri = payload.data?.data
|
|
93
|
+
if (uri != null) {
|
|
94
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
95
|
+
PdfKingManager.getInstance().handleUriSelection(uri)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
125
99
|
}
|
|
126
|
-
}
|
|
127
100
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
promise.resolve(result)
|
|
133
|
-
} catch (e: Exception) {
|
|
134
|
-
promise.reject("ERR_BITMAP", e.message, e)
|
|
101
|
+
AsyncFunction("pickFile") {
|
|
102
|
+
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
|
103
|
+
type = "application/pdf"
|
|
104
|
+
addCategory(Intent.CATEGORY_OPENABLE)
|
|
135
105
|
}
|
|
106
|
+
appContext.currentActivity?.startActivityForResult(intent, FILE_PICKER_REQUEST_CODE)
|
|
136
107
|
}
|
|
137
|
-
}
|
|
138
108
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
109
|
+
AsyncFunction("loadPdf") { path: String ->
|
|
110
|
+
val file = File(path)
|
|
111
|
+
if (file.exists()) {
|
|
112
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
113
|
+
try {
|
|
114
|
+
val pdfKing = PdfKingManager.getInstance()
|
|
115
|
+
withContext(Dispatchers.Main) {
|
|
116
|
+
pdfKing.onFileLoadStarted?.invoke()
|
|
117
|
+
}
|
|
118
|
+
pdfKing.loadPdf(file)
|
|
119
|
+
val count = pdfKing.getPageCountSync()
|
|
120
|
+
|
|
121
|
+
withContext(Dispatchers.Main) {
|
|
122
|
+
pdfKing.onFileLoadSuccess?.invoke(path, file.name, count)
|
|
123
|
+
}
|
|
124
|
+
} catch (e: Exception) {
|
|
125
|
+
this@RnPdfKingModule.sendEvent(
|
|
126
|
+
"onPdfLoadError",
|
|
127
|
+
mapOf("message" to (e.message ?: "Unknown error"))
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
this@RnPdfKingModule.sendEvent("onPdfLoadError", mapOf("message" to "File does not exist"))
|
|
146
133
|
}
|
|
147
134
|
}
|
|
148
|
-
}
|
|
149
135
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
136
|
+
AsyncFunction("getPageBitmapBase64") { pageNo: Int, promise: Promise ->
|
|
137
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
138
|
+
try {
|
|
139
|
+
val result = PdfKingManager.getInstance().getPageBitmapBase64(pageNo)
|
|
140
|
+
promise.resolve(result)
|
|
141
|
+
} catch (e: Exception) {
|
|
142
|
+
promise.reject("ERR_BITMAP", e.message, e)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
AsyncFunction("getTextChars") { pageNo: Int, promise: Promise ->
|
|
148
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
149
|
+
try {
|
|
150
|
+
val result = PdfKingManager.getInstance().getPageText(pageNo)
|
|
151
|
+
promise.resolve(result)
|
|
152
|
+
} catch (e: Exception) {
|
|
153
|
+
promise.reject("ERR_TEXT", e.message, e)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
View(RnPdfKingView::class) {
|
|
159
|
+
Prop("pageNo") { view: RnPdfKingView, pageNo: Int ->
|
|
160
|
+
view.setPage(pageNo)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Prop("mode") { view: RnPdfKingView, mode: String ->
|
|
164
|
+
view.setMode(mode)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Prop("pdfWidth") { view: RnPdfKingView, width: Int ->
|
|
168
|
+
view.setPdfWidth(width)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
Prop("pdfHeight") { view: RnPdfKingView, height: Int ->
|
|
172
|
+
view.setPdfHeight(height)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Prop("preDefinedHighlights") { view: RnPdfKingView, highlights: List<Map<String, Any>> ->
|
|
176
|
+
view.setHighlights(highlights)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Prop("preDefinedDottedHighlights") { view: RnPdfKingView, highlights: List<Map<String, Any>> ->
|
|
180
|
+
view.setDottedHighlights(highlights)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
AsyncFunction("clearSelection") { view: RnPdfKingView ->
|
|
184
|
+
view.clearSelection()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
Prop("handleColor") { view: RnPdfKingView, color: Int ->
|
|
188
|
+
view.setHandleColor(color)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
Prop("selectionColor") { view: RnPdfKingView, color: Int ->
|
|
192
|
+
view.setSelectionColor(color)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
Prop("selectionEnabled") { view: RnPdfKingView, enabled: Boolean ->
|
|
196
|
+
view.setSelectionEnabled(enabled)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
Events("onSelectionChanged", "onSelectionStarted", "onSelectionEnded", "onPreDefinedHighlightClick")
|
|
200
|
+
}
|
|
192
201
|
}
|
|
193
|
-
}
|
|
194
202
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-pdf-king",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "The one and only best pdf library that efficiently handle 1000 page pdf with memeory mangement , easy selection , very customizable and allow pdf to edit",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|