@june24/expo-pdf-reader 0.1.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.
- package/README.md +50 -0
- package/android/build.gradle +23 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/pdfreader/ExpoPdfReaderModule.kt +202 -0
- package/android/src/main/java/expo/modules/pdfreader/ExpoPdfReaderView.kt +934 -0
- package/build/ExpoPdfReader.types.d.ts +85 -0
- package/build/ExpoPdfReader.types.d.ts.map +1 -0
- package/build/ExpoPdfReader.types.js +2 -0
- package/build/ExpoPdfReader.types.js.map +1 -0
- package/build/ExpoPdfReaderView.d.ts +28 -0
- package/build/ExpoPdfReaderView.d.ts.map +1 -0
- package/build/ExpoPdfReaderView.js +107 -0
- package/build/ExpoPdfReaderView.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +16 -0
- package/ios/ExpoPdfReader.podspec +27 -0
- package/ios/ExpoPdfReaderModule.swift +170 -0
- package/ios/ExpoPdfReaderView.swift +675 -0
- package/package.json +37 -0
- package/src/ExpoPdfReader.types.ts +99 -0
- package/src/ExpoPdfReaderView.tsx +137 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# expo-pdf-reader
|
|
2
|
+
|
|
3
|
+
A PDF reader for Expo.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install expo-pdf-reader
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { StyleSheet, View } from 'react-native';
|
|
15
|
+
import { ExpoPdfReaderView } from 'expo-pdf-reader';
|
|
16
|
+
|
|
17
|
+
export default function App() {
|
|
18
|
+
return (
|
|
19
|
+
<View style={styles.container}>
|
|
20
|
+
<ExpoPdfReaderView
|
|
21
|
+
style={styles.pdf}
|
|
22
|
+
url="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
|
|
23
|
+
/>
|
|
24
|
+
</View>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const styles = StyleSheet.create({
|
|
29
|
+
container: {
|
|
30
|
+
flex: 1,
|
|
31
|
+
backgroundColor: '#fff',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
},
|
|
35
|
+
pdf: {
|
|
36
|
+
flex: 1,
|
|
37
|
+
width: '100%',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
### Android
|
|
45
|
+
|
|
46
|
+
No additional configuration required.
|
|
47
|
+
|
|
48
|
+
### iOS
|
|
49
|
+
|
|
50
|
+
No additional configuration required.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
|
|
4
|
+
group = 'expo.modules.pdfreader'
|
|
5
|
+
version = '0.1.0'
|
|
6
|
+
|
|
7
|
+
android {
|
|
8
|
+
compileSdkVersion 35
|
|
9
|
+
defaultConfig {
|
|
10
|
+
minSdkVersion 24
|
|
11
|
+
targetSdkVersion 35
|
|
12
|
+
versionCode 1
|
|
13
|
+
versionName "0.1.0"
|
|
14
|
+
}
|
|
15
|
+
lintOptions {
|
|
16
|
+
abortOnError false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
dependencies {
|
|
21
|
+
implementation project(':expo-modules-core')
|
|
22
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.24"
|
|
23
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
package expo.modules.pdfreader
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.modules.Module
|
|
4
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
|
+
import expo.modules.kotlin.Promise
|
|
6
|
+
import expo.modules.kotlin.records.Field
|
|
7
|
+
import expo.modules.kotlin.records.Record
|
|
8
|
+
|
|
9
|
+
class AnnotationData : Record {
|
|
10
|
+
@Field
|
|
11
|
+
var type: String = "pen"
|
|
12
|
+
@Field
|
|
13
|
+
var color: String = "#000000"
|
|
14
|
+
@Field
|
|
15
|
+
var page: Int = 0
|
|
16
|
+
@Field
|
|
17
|
+
var points: List<List<Map<String, Double>>> = emptyList()
|
|
18
|
+
@Field
|
|
19
|
+
var width: Double = 10.0
|
|
20
|
+
@Field
|
|
21
|
+
var text: String = ""
|
|
22
|
+
@Field
|
|
23
|
+
var fontSize: Double = 16.0
|
|
24
|
+
@Field
|
|
25
|
+
var x: Double = 0.0
|
|
26
|
+
@Field
|
|
27
|
+
var y: Double = 0.0
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class SearchResultData : Record {
|
|
31
|
+
@Field
|
|
32
|
+
var page: Int = 0
|
|
33
|
+
@Field
|
|
34
|
+
var x: Double = 0.0
|
|
35
|
+
@Field
|
|
36
|
+
var y: Double = 0.0
|
|
37
|
+
@Field
|
|
38
|
+
var width: Double = 0.0
|
|
39
|
+
@Field
|
|
40
|
+
var height: Double = 0.0
|
|
41
|
+
@Field
|
|
42
|
+
var textSnippet: String = ""
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class ExpoPdfReaderModule : Module() {
|
|
46
|
+
override fun definition() = ModuleDefinition {
|
|
47
|
+
Name("ExpoPdfReader")
|
|
48
|
+
|
|
49
|
+
View(ExpoPdfReaderView::class) {
|
|
50
|
+
Events("onAnnotationChange", "onPageChange", "onScroll")
|
|
51
|
+
|
|
52
|
+
Prop("url") { view: ExpoPdfReaderView, url: String ->
|
|
53
|
+
view.setUrl(url)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Prop("displayMode") { view: ExpoPdfReaderView, mode: String ->
|
|
57
|
+
view.setDisplayMode(mode)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Prop("initialPage") { view: ExpoPdfReaderView, page: Int ->
|
|
61
|
+
view.setInitialPage(page)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Prop("minZoom") { view: ExpoPdfReaderView, value: Double ->
|
|
65
|
+
view.setMinZoom(value)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Prop("maxZoom") { view: ExpoPdfReaderView, value: Double ->
|
|
69
|
+
view.setMaxZoom(value)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Prop("annotationTool") { view: ExpoPdfReaderView, tool: String ->
|
|
73
|
+
view.setAnnotationTool(tool)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Prop("annotationColor") { view: ExpoPdfReaderView, color: String? ->
|
|
77
|
+
view.setAnnotationColor(color)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Prop("annotationFontSize") { view: ExpoPdfReaderView, size: Double ->
|
|
81
|
+
view.setAnnotationFontSize(size)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Prop("annotationText") { view: ExpoPdfReaderView, text: String ->
|
|
85
|
+
view.setAnnotationText(text)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Prop("annotationStrokeWidth") { view: ExpoPdfReaderView, width: Double ->
|
|
89
|
+
view.setAnnotationStrokeWidth(width)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Prop("initialAnnotations") { view: ExpoPdfReaderView, annotations: List<AnnotationData> ->
|
|
93
|
+
view.setAnnotations(annotations)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
AsyncFunction("save") { viewTag: Int, promise: Promise ->
|
|
98
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
99
|
+
if (view == null) {
|
|
100
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
101
|
+
return@AsyncFunction
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
val path = view.savePdf()
|
|
106
|
+
promise.resolve(path)
|
|
107
|
+
} catch (e: Exception) {
|
|
108
|
+
promise.reject("ERR_SAVE_FAILED", "Failed to save PDF: ${e.message}", e)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
AsyncFunction("getAnnotations") { viewTag: Int, promise: Promise ->
|
|
113
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
114
|
+
if (view == null) {
|
|
115
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
116
|
+
return@AsyncFunction
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
promise.resolve(view.getAnnotations())
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
AsyncFunction("searchText") { viewTag: Int, text: String, promise: Promise ->
|
|
123
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
124
|
+
if (view == null) {
|
|
125
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
126
|
+
return@AsyncFunction
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
promise.resolve(view.searchText(text))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
AsyncFunction("goToPage") { viewTag: Int, page: Int, promise: Promise ->
|
|
133
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
134
|
+
if (view == null) {
|
|
135
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
136
|
+
return@AsyncFunction
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
view.goToPage(page)
|
|
140
|
+
promise.resolve(null)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
AsyncFunction("undo") { viewTag: Int, promise: Promise ->
|
|
144
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
145
|
+
if (view == null) {
|
|
146
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
147
|
+
return@AsyncFunction
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
val success = view.undo()
|
|
151
|
+
promise.resolve(success)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
AsyncFunction("redo") { viewTag: Int, promise: Promise ->
|
|
155
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
156
|
+
if (view == null) {
|
|
157
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
158
|
+
return@AsyncFunction
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
val success = view.redo()
|
|
162
|
+
promise.resolve(success)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
AsyncFunction("zoomIn") { viewTag: Int, promise: Promise ->
|
|
166
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
167
|
+
if (view == null) {
|
|
168
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
169
|
+
return@AsyncFunction
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
val changed = view.zoomIn()
|
|
173
|
+
promise.resolve(changed)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
AsyncFunction("zoomOut") { viewTag: Int, promise: Promise ->
|
|
177
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
178
|
+
if (view == null) {
|
|
179
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
180
|
+
return@AsyncFunction
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
val changed = view.zoomOut()
|
|
184
|
+
promise.resolve(changed)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
AsyncFunction("renderThumbnail") { viewTag: Int, page: Int, width: Int, promise: Promise ->
|
|
188
|
+
val view = appContext.findView<ExpoPdfReaderView>(viewTag)
|
|
189
|
+
if (view == null) {
|
|
190
|
+
promise.reject("ERR_VIEW_NOT_FOUND", "Could not find view with tag $viewTag", null)
|
|
191
|
+
return@AsyncFunction
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
val path = view.renderThumbnail(page, width)
|
|
196
|
+
promise.resolve(path)
|
|
197
|
+
} catch (e: Exception) {
|
|
198
|
+
promise.reject("ERR_THUMBNAIL_FAILED", "Failed to render thumbnail: ${e.message}", e)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|