rn-pdf-king 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.
Files changed (84) hide show
  1. package/.eslintrc.js +5 -0
  2. package/README.md +148 -0
  3. package/android/build.gradle +55 -0
  4. package/android/src/main/AndroidManifest.xml +2 -0
  5. package/android/src/main/java/expo/modules/rnpdfking/PdfKing.kt +693 -0
  6. package/android/src/main/java/expo/modules/rnpdfking/RnPdfKingModule.kt +163 -0
  7. package/android/src/main/java/expo/modules/rnpdfking/RnPdfKingView.kt +184 -0
  8. package/build/PdfDocument.d.ts +19 -0
  9. package/build/PdfDocument.d.ts.map +1 -0
  10. package/build/PdfDocument.js +81 -0
  11. package/build/PdfDocument.js.map +1 -0
  12. package/build/PdfPage.d.ts +24 -0
  13. package/build/PdfPage.d.ts.map +1 -0
  14. package/build/PdfPage.js +13 -0
  15. package/build/PdfPage.js.map +1 -0
  16. package/build/RnPdfKing.types.d.ts +48 -0
  17. package/build/RnPdfKing.types.d.ts.map +1 -0
  18. package/build/RnPdfKing.types.js +2 -0
  19. package/build/RnPdfKing.types.js.map +1 -0
  20. package/build/RnPdfKingModule.d.ts +13 -0
  21. package/build/RnPdfKingModule.d.ts.map +1 -0
  22. package/build/RnPdfKingModule.js +4 -0
  23. package/build/RnPdfKingModule.js.map +1 -0
  24. package/build/RnPdfKingModule.web.d.ts +13 -0
  25. package/build/RnPdfKingModule.web.d.ts.map +1 -0
  26. package/build/RnPdfKingModule.web.js +21 -0
  27. package/build/RnPdfKingModule.web.js.map +1 -0
  28. package/build/RnPdfKingView.d.ts +4 -0
  29. package/build/RnPdfKingView.d.ts.map +1 -0
  30. package/build/RnPdfKingView.js +7 -0
  31. package/build/RnPdfKingView.js.map +1 -0
  32. package/build/RnPdfKingView.web.d.ts +4 -0
  33. package/build/RnPdfKingView.web.d.ts.map +1 -0
  34. package/build/RnPdfKingView.web.js +7 -0
  35. package/build/RnPdfKingView.web.js.map +1 -0
  36. package/build/ZoomableList.d.ts +37 -0
  37. package/build/ZoomableList.d.ts.map +1 -0
  38. package/build/ZoomableList.js +289 -0
  39. package/build/ZoomableList.js.map +1 -0
  40. package/build/ZoomablePage.d.ts +10 -0
  41. package/build/ZoomablePage.d.ts.map +1 -0
  42. package/build/ZoomablePage.js +15 -0
  43. package/build/ZoomablePage.js.map +1 -0
  44. package/build/ZoomablePdfPage.d.ts +10 -0
  45. package/build/ZoomablePdfPage.d.ts.map +1 -0
  46. package/build/ZoomablePdfPage.js +17 -0
  47. package/build/ZoomablePdfPage.js.map +1 -0
  48. package/build/index.d.ts +8 -0
  49. package/build/index.d.ts.map +1 -0
  50. package/build/index.js +10 -0
  51. package/build/index.js.map +1 -0
  52. package/build/zoom/constants.d.ts +36 -0
  53. package/build/zoom/constants.d.ts.map +1 -0
  54. package/build/zoom/constants.js +36 -0
  55. package/build/zoom/constants.js.map +1 -0
  56. package/build/zoom/index.d.ts +255 -0
  57. package/build/zoom/index.d.ts.map +1 -0
  58. package/build/zoom/index.js +783 -0
  59. package/build/zoom/index.js.map +1 -0
  60. package/build/zoom/utils.d.ts +55 -0
  61. package/build/zoom/utils.d.ts.map +1 -0
  62. package/build/zoom/utils.js +66 -0
  63. package/build/zoom/utils.js.map +1 -0
  64. package/bun.lock +2217 -0
  65. package/expo-module.config.json +9 -0
  66. package/ios/RnPdfKing.podspec +29 -0
  67. package/ios/RnPdfKingModule.swift +48 -0
  68. package/ios/RnPdfKingView.swift +38 -0
  69. package/package.json +45 -0
  70. package/src/PdfDocument.tsx +115 -0
  71. package/src/PdfPage.tsx +57 -0
  72. package/src/RnPdfKing.types.ts +32 -0
  73. package/src/RnPdfKingModule.ts +15 -0
  74. package/src/RnPdfKingModule.web.ts +24 -0
  75. package/src/RnPdfKingView.tsx +11 -0
  76. package/src/RnPdfKingView.web.tsx +15 -0
  77. package/src/ZoomableList.tsx +438 -0
  78. package/src/ZoomablePage.tsx +31 -0
  79. package/src/ZoomablePdfPage.tsx +34 -0
  80. package/src/index.ts +9 -0
  81. package/src/zoom/constants.ts +40 -0
  82. package/src/zoom/index.tsx +1267 -0
  83. package/src/zoom/utils.ts +96 -0
  84. package/tsconfig.json +9 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['universe/native', 'universe/web'],
4
+ ignorePatterns: ['build'],
5
+ };
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # rn-pdf-king
2
+
3
+ The ultimate PDF library for React Native and Expo. Efficiently handles large PDFs (1000+ pages) with memory management, smooth text selection, customizable highlights, and system-level file integration.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **High Performance:** Memory-efficient rendering for large documents.
8
+ - 🔍 **Text Selection:** Native text selection with customizable handles and selection colors.
9
+ - 🖍️ **Highlights:** Support for predefined highlights with click events.
10
+ - 📁 **System Integration:** Open PDFs directly from other apps via system intents.
11
+ - 📱 **Expo Compatible:** Built with Expo Modules API.
12
+ - 🔭 **Zoom Ready:** Works seamlessly with `react-native-zoom-reanimated` or `react-native-zoom-toolkit`.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ bun add rn-pdf-king
18
+ ```
19
+
20
+ *Note: Ensure you have `react-native-gesture-handler` and `react-native-reanimated` installed if you plan to use zooming features.*
21
+
22
+ ## Configuration (Android Only)
23
+
24
+ To allow your app to open PDF files from the system, add the following to your `app.json` or `app.config.js`:
25
+
26
+ ```json
27
+ {
28
+ "expo": {
29
+ "android": {
30
+ "intentFilters": [
31
+ {
32
+ "action": "VIEW",
33
+ "category": ["DEFAULT", "BROWSABLE"],
34
+ "data": [
35
+ { "scheme": "file", "mimeType": "application/pdf" },
36
+ { "scheme": "content", "mimeType": "application/pdf" }
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ Then run `npx expo prebuild`.
46
+
47
+ ## Usage
48
+
49
+ ### 1. Setup Provider
50
+ Wrap your application with `PdfDocumentProvider` to manage document state.
51
+
52
+ ```tsx
53
+ import { PdfDocumentProvider } from 'rn-pdf-king';
54
+
55
+ export default function App() {
56
+ return (
57
+ <PdfDocumentProvider>
58
+ <MyPdfViewer />
59
+ </PdfDocumentProvider>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### 2. Access Document State
65
+ Use the `usePdfDocument` hook to handle file picking and monitor loading states.
66
+
67
+ ```tsx
68
+ import { usePdfDocument } from 'rn-pdf-king';
69
+
70
+ const MyPdfViewer = () => {
71
+ const {
72
+ loading,
73
+ pageCount,
74
+ filePath,
75
+ fileName,
76
+ pickFile,
77
+ error
78
+ } = usePdfDocument();
79
+
80
+ if (loading) return <ActivityIndicator />;
81
+ if (!filePath) return <Button title="Pick PDF" onPress={pickFile} />;
82
+
83
+ return <Text>Loaded: {fileName}</Text>;
84
+ };
85
+ ```
86
+
87
+ ### 3. Render PDF Pages
88
+ Use the `PdfPage` component to display specific pages. It supports advanced features like text selection and highlights.
89
+
90
+ ```tsx
91
+ import { PdfPage } from 'rn-pdf-king';
92
+
93
+ <PdfPage
94
+ pageNo={1}
95
+ width={300}
96
+ height={424}
97
+ handleColor="green"
98
+ selectionColor="rgba(0, 255, 0, 0.3)"
99
+ preDefinedHighlights={[
100
+ { id: 'h1', startIndex: 10, endIndex: 50, color: 'yellow' }
101
+ ]}
102
+ onSelectionChanged={(e) => console.log('Selected:', e.nativeEvent.selectedText)}
103
+ onPreDefinedHighlightClick={(e) => alert(`Clicked highlight: ${e.nativeEvent.id}`)}
104
+ />
105
+ ```
106
+
107
+ ### 4. Handling System Intents
108
+ To handle PDFs opened from other apps, check the initial intent on mount.
109
+
110
+ ```tsx
111
+ import RnPdfKing from 'rn-pdf-king';
112
+
113
+ useEffect(() => {
114
+ if (Platform.OS === 'android') {
115
+ RnPdfKing.checkInitialIntent();
116
+ }
117
+ }, []);
118
+ ```
119
+
120
+ ## API Reference
121
+
122
+ ### `PdfPage` Props
123
+
124
+ | Prop | Type | Description |
125
+ | :--- | :--- | :--- |
126
+ | `pageNo` | `number` | The page number to render (1-indexed). |
127
+ | `width` | `number` | Page width. |
128
+ | `height` | `number` | Page height. |
129
+ | `preDefinedHighlights` | `Highlight[]` | Array of highlights to render on the page. |
130
+ | `handleColor` | `ColorValue` | Color of the selection handles. |
131
+ | `selectionColor` | `ColorValue` | Color of the selection rectangle. |
132
+ | `onSelectionChanged` | `Function` | Callback triggered when text selection changes. |
133
+ | `onSelectionStarted` | `Function` | Callback triggered when selection starts (long press). |
134
+ | `onSelectionEnded` | `Function` | Callback triggered when selection ends. |
135
+ | `onPreDefinedHighlightClick` | `Function` | Callback triggered when a highlight is tapped. |
136
+
137
+ ### `Highlight` Object
138
+
139
+ | Key | Type | Description |
140
+ | :--- | :--- | :--- |
141
+ | `id` | `string` | Unique identifier for the highlight. |
142
+ | `startIndex` | `number` | Character start index. |
143
+ | `endIndex` | `number` | Character end index. |
144
+ | `color` | `ColorValue` | Background color of the highlight. |
145
+
146
+ ## License
147
+
148
+ MIT
@@ -0,0 +1,55 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'org.jetbrains.kotlin.plugin.compose' version '2.0.21'
4
+ id 'expo-module-gradle-plugin'
5
+ }
6
+
7
+ group = 'expo.modules.rnpdfking'
8
+ version = '0.1.0'
9
+
10
+ android {
11
+ namespace "expo.modules.rnpdfking"
12
+ defaultConfig {
13
+ versionCode 1
14
+ versionName "0.1.0"
15
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16
+ }
17
+ lintOptions {
18
+ abortOnError false
19
+ }
20
+
21
+ buildFeatures {
22
+ compose = true
23
+ }
24
+
25
+ compileOptions {
26
+ sourceCompatibility = JavaVersion.VERSION_11
27
+ targetCompatibility = JavaVersion.VERSION_11
28
+ }
29
+ }
30
+
31
+ dependencies {
32
+ implementation "androidx.core:core-ktx:1.13.1"
33
+ implementation "androidx.appcompat:appcompat:1.7.0"
34
+ implementation "androidx.activity:activity-ktx:1.9.1"
35
+ implementation "androidx.lifecycle:lifecycle-runtime:2.8.4"
36
+ implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.4"
37
+ implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4"
38
+ implementation "androidx.savedstate:savedstate-ktx:1.2.1"
39
+ implementation "androidx.activity:activity-compose:1.9.1"
40
+ implementation platform("androidx.compose:compose-bom:2024.09.00")
41
+ implementation "androidx.compose.ui:ui"
42
+ implementation "androidx.compose.ui:ui-graphics"
43
+ implementation "androidx.compose.ui:ui-tooling-preview"
44
+ implementation "androidx.compose.material3:material3"
45
+
46
+ implementation "com.tom-roush:pdfbox-android:2.0.27.0"
47
+
48
+ testImplementation "junit:junit:4.13.2"
49
+ androidTestImplementation "androidx.test.ext:junit:1.3.0"
50
+ androidTestImplementation "androidx.test.espresso:espresso-core:3.7.0"
51
+ androidTestImplementation platform("androidx.compose:compose-bom:2024.09.00")
52
+ androidTestImplementation "androidx.compose.ui:ui-test-junit4"
53
+ debugImplementation "androidx.compose.ui:ui-tooling"
54
+ debugImplementation "androidx.compose.ui:ui-test-manifest"
55
+ }
@@ -0,0 +1,2 @@
1
+ <manifest>
2
+ </manifest>