@kishannareshpal/expo-pdf 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/.editorconfig +12 -0
- package/.eslintrc.js +2 -0
- package/.node-version +1 -0
- package/.prettierignore +31 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +271 -0
- package/LICENSE +21 -0
- package/README.md +243 -0
- package/android/build.gradle +55 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/com/kishannareshpal/expopdf/.editorconfig +12 -0
- package/android/src/main/java/com/kishannareshpal/expopdf/KJExpoPdfModule.kt +60 -0
- package/android/src/main/java/com/kishannareshpal/expopdf/KJExpoPdfView.kt +222 -0
- package/android/src/main/java/com/kishannareshpal/expopdf/lib/ContentPadding.kt +23 -0
- package/android/src/main/java/com/kishannareshpal/expopdf/lib/FitMode.kt +18 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/build/pdf-module.d.ts +7 -0
- package/build/pdf-module.d.ts.map +1 -0
- package/build/pdf-module.js +4 -0
- package/build/pdf-module.js.map +1 -0
- package/build/pdf-view.d.ts +25 -0
- package/build/pdf-view.d.ts.map +1 -0
- package/build/pdf-view.js +14 -0
- package/build/pdf-view.js.map +1 -0
- package/build/types.d.ts +20 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/utils.d.ts +3 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +10 -0
- package/build/utils.js.map +1 -0
- package/bun.lock +2278 -0
- package/eslint.config.js +5 -0
- package/expo-module.config.json +16 -0
- package/ios/KJExpoPdf.podspec +29 -0
- package/ios/KJExpoPdfModule.swift +51 -0
- package/ios/KJExpoPdfView.swift +242 -0
- package/ios/extensions/PdfViewExtensions.swift +94 -0
- package/ios/lib/ContentPadding.swift +26 -0
- package/ios/lib/FitMode.swift +14 -0
- package/package.json +60 -0
- package/src/index.ts +4 -0
- package/src/pdf-module.ts +8 -0
- package/src/pdf-view.tsx +68 -0
- package/src/types.ts +16 -0
- package/src/utils.ts +12 -0
- package/tsconfig.json +9 -0
package/.editorconfig
ADDED
package/.eslintrc.js
ADDED
package/.node-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v24.12.0
|
package/.prettierignore
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
**/node_modules/
|
|
4
|
+
|
|
5
|
+
# Build outputs
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
*.tgz
|
|
9
|
+
|
|
10
|
+
# iOS
|
|
11
|
+
ios/Pods/
|
|
12
|
+
ios/build/
|
|
13
|
+
*.xcworkspace
|
|
14
|
+
*.xcodeproj
|
|
15
|
+
|
|
16
|
+
# Android
|
|
17
|
+
android/build/
|
|
18
|
+
android/.gradle/
|
|
19
|
+
android/.idea/
|
|
20
|
+
*.iml
|
|
21
|
+
|
|
22
|
+
# Generated files
|
|
23
|
+
*.generated.*
|
|
24
|
+
.expo/
|
|
25
|
+
.expo-shared/
|
|
26
|
+
|
|
27
|
+
# Lock files
|
|
28
|
+
package-lock.json
|
|
29
|
+
yarn.lock
|
|
30
|
+
bun.lock
|
|
31
|
+
pnpm-lock.yaml
|
package/.prettierrc
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unpublished
|
|
4
|
+
|
|
5
|
+
### 🛠 Breaking changes
|
|
6
|
+
### 🎉 New features
|
|
7
|
+
### 🐛 Bug fixes
|
|
8
|
+
### 💡 Others
|
|
9
|
+
|
|
10
|
+
_This version does not introduce any user-facing changes._
|
|
11
|
+
|
|
12
|
+
## 0.1.0 - 2026-01-06
|
|
13
|
+
|
|
14
|
+
_Initial release with all features documented in README.md_
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Contributing to @kishannareshpal/expo-pdf
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to `@kishannarehpal/expo-pdf`! This document provides guidelines and instructions for contributing to the project.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Contributing to @kishannareshpal/expo-pdf](#contributing-to-kishannareshpalexpo-pdf)
|
|
8
|
+
- [Table of Contents](#table-of-contents)
|
|
9
|
+
- [Code of Conduct](#code-of-conduct)
|
|
10
|
+
- [Getting Started](#getting-started)
|
|
11
|
+
- [Development Setup](#development-setup)
|
|
12
|
+
- [Prerequisites](#prerequisites)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Edit the module source code](#edit-the-module-source-code)
|
|
15
|
+
- [TypeScript](#typescript)
|
|
16
|
+
- [Android](#android)
|
|
17
|
+
- [iOS](#ios)
|
|
18
|
+
- [Resources](#resources)
|
|
19
|
+
- [Running the Example App](#running-the-example-app)
|
|
20
|
+
- [Code Style Guidelines](#code-style-guidelines)
|
|
21
|
+
- [Testing](#testing)
|
|
22
|
+
- [Manual Testing](#manual-testing)
|
|
23
|
+
- [Submitting Changes](#submitting-changes)
|
|
24
|
+
- [Before Submitting](#before-submitting)
|
|
25
|
+
- [Pull Request Process](#pull-request-process)
|
|
26
|
+
- [Pull Request Guidelines](#pull-request-guidelines)
|
|
27
|
+
- [Reporting Bugs](#reporting-bugs)
|
|
28
|
+
- [Requesting Features](#requesting-features)
|
|
29
|
+
- [Questions?](#questions)
|
|
30
|
+
|
|
31
|
+
## Code of Conduct
|
|
32
|
+
|
|
33
|
+
This project adheres to a code of conduct that all contributors are expected to follow. Please be respectful and constructive in all interactions.
|
|
34
|
+
|
|
35
|
+
## Getting Started
|
|
36
|
+
|
|
37
|
+
Before you begin:
|
|
38
|
+
|
|
39
|
+
1. **Fork the repository** on GitHub
|
|
40
|
+
2. **Clone your fork** locally:
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/your-username/expo-pdf.git
|
|
43
|
+
cd expo-pdf
|
|
44
|
+
```
|
|
45
|
+
3. **Add the upstream repository**:
|
|
46
|
+
```bash
|
|
47
|
+
git remote add upstream https://github.com/kishannareshpal/expo-pdf.git
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Development Setup
|
|
51
|
+
|
|
52
|
+
### Prerequisites
|
|
53
|
+
|
|
54
|
+
- **bun** (https://bun.com/)
|
|
55
|
+
- **For iOS development**:
|
|
56
|
+
- macOS (required)
|
|
57
|
+
- Xcode (latest stable version)
|
|
58
|
+
- CocoaPods: `sudo gem install cocoapods`
|
|
59
|
+
- **For Android development**:
|
|
60
|
+
- Android Studio
|
|
61
|
+
- Android SDK and build tools
|
|
62
|
+
- Java Development Kit (JDK)
|
|
63
|
+
|
|
64
|
+
### Installation
|
|
65
|
+
|
|
66
|
+
1. **Install root dependencies**:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bun install
|
|
70
|
+
```
|
|
71
|
+
2. **Install example app dependencies**:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cd example
|
|
75
|
+
bun install
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Edit the module source code
|
|
79
|
+
|
|
80
|
+
#### TypeScript
|
|
81
|
+
|
|
82
|
+
Edit the React Native binding TypeScript files from `src/` using your favorite editor, such as VS Code.
|
|
83
|
+
|
|
84
|
+
#### Android
|
|
85
|
+
|
|
86
|
+
Edit the Android native files by opening Android Studio: `bun open:android`
|
|
87
|
+
|
|
88
|
+

|
|
89
|
+
|
|
90
|
+
#### iOS
|
|
91
|
+
|
|
92
|
+
Edit the iOS native files by opening Xcode: `bun open:ios`
|
|
93
|
+
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+
#### Resources
|
|
97
|
+
|
|
98
|
+
The following resources may be helpful as they represent the core of the project:
|
|
99
|
+
|
|
100
|
+
- [`Expo Modules API` documentation](https://docs.expo.dev/modules/module-api/)
|
|
101
|
+
- [`Apple PDFKit` documentation](https://developer.apple.com/documentation/pdfkit)
|
|
102
|
+
- [`AndroidX PDF` documentation](https://developer.android.com/jetpack/androidx/releases/pdf)
|
|
103
|
+
|
|
104
|
+
### Running the Example App
|
|
105
|
+
|
|
106
|
+
The `example/` directory contains a test app to develop and test the changes you make in the module. For example, if you make a change to either the Android / iOS native module, you will need to re-build and re-install the app on the device - this can be easily achieved by following:
|
|
107
|
+
|
|
108
|
+
1. Start the Metro bundler (if not already):
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
cd example
|
|
112
|
+
bun start
|
|
113
|
+
```
|
|
114
|
+
2. Install and run the app on iOS:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
cd example
|
|
118
|
+
bun ios
|
|
119
|
+
```
|
|
120
|
+
3. Install and run the app on Android:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
cd example
|
|
124
|
+
bun android
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Code Style Guidelines
|
|
128
|
+
|
|
129
|
+
1. **TypeScript/React**:
|
|
130
|
+
|
|
131
|
+
- Use functional components with hooks
|
|
132
|
+
- Prefer `const` over `let` when possible
|
|
133
|
+
- Use meaningful, self-documenting variable and function names
|
|
134
|
+
- Add TSDoc comments for public APIs when necessary
|
|
135
|
+
2. **Swift**:
|
|
136
|
+
|
|
137
|
+
- Follow Swift style guide conventions
|
|
138
|
+
- Use meaningful, self-documenting names for classes, functions, and variables
|
|
139
|
+
- Add documentation comments for public APIs
|
|
140
|
+
3. **Kotlin**:
|
|
141
|
+
|
|
142
|
+
- Follow Kotlin style guide conventions
|
|
143
|
+
- Use meaningful names for classes, functions, and variables
|
|
144
|
+
- Add KDoc comments for public APIs
|
|
145
|
+
4. **General**:
|
|
146
|
+
|
|
147
|
+
- Keep functions focused and small
|
|
148
|
+
- Write self-documenting code
|
|
149
|
+
- Comment complex logic
|
|
150
|
+
- Maintain consistency with existing codebase
|
|
151
|
+
|
|
152
|
+
## Testing
|
|
153
|
+
|
|
154
|
+
### Manual Testing
|
|
155
|
+
|
|
156
|
+
1. Use the example app to manually test your changes
|
|
157
|
+
2. Test on both iOS and Android platforms
|
|
158
|
+
|
|
159
|
+
## Submitting Changes
|
|
160
|
+
|
|
161
|
+
### Before Submitting
|
|
162
|
+
|
|
163
|
+
1. **Update the CHANGELOG.md**:
|
|
164
|
+
|
|
165
|
+
- Add your changes under the appropriate version
|
|
166
|
+
- Use the following format:
|
|
167
|
+
- `### 🎉 New features` for new features
|
|
168
|
+
- `### 🐛 Bug fixes` for bug fixes
|
|
169
|
+
- `### 💡 Others` for other changes
|
|
170
|
+
- `### 🛠 Breaking changes` for breaking changes
|
|
171
|
+
2. **Test your changes**:
|
|
172
|
+
|
|
173
|
+
- Test on iOS
|
|
174
|
+
- Test on Android
|
|
175
|
+
- Verify the example app works correctly
|
|
176
|
+
|
|
177
|
+
### Pull Request Process
|
|
178
|
+
|
|
179
|
+
1. **Create a branch** from `main`:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
git checkout -b feature/your-feature-name
|
|
183
|
+
# or
|
|
184
|
+
git checkout -b username/your-bug-fix
|
|
185
|
+
```
|
|
186
|
+
2. **Make your changes**:
|
|
187
|
+
|
|
188
|
+
- Write clean, well-documented code
|
|
189
|
+
- Follow existing code patterns
|
|
190
|
+
- Add tests if applicable
|
|
191
|
+
- Update documentation as needed
|
|
192
|
+
3. **Commit your changes**:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
git add .
|
|
196
|
+
git commit -m "feat: add support for password-protected PDFs"
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Use conventional commit messages:
|
|
200
|
+
|
|
201
|
+
- `feat:` for new features
|
|
202
|
+
- `fix:` for bug fixes
|
|
203
|
+
- `docs:` for documentation changes
|
|
204
|
+
- `style:` for formatting changes
|
|
205
|
+
- `refactor:` for code refactoring
|
|
206
|
+
- `test:` for adding tests
|
|
207
|
+
- `chore:` for maintenance tasks
|
|
208
|
+
4. **Push to your fork**:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
git push origin feature/your-feature-name
|
|
212
|
+
```
|
|
213
|
+
5. **Create a Pull Request**:
|
|
214
|
+
|
|
215
|
+
- Go to the GitHub repository
|
|
216
|
+
- Click "New Pull Request"
|
|
217
|
+
- Select your branch
|
|
218
|
+
- Fill out the PR template with:
|
|
219
|
+
- Description of changes
|
|
220
|
+
- Testing performed
|
|
221
|
+
- Screenshots/videos if applicable
|
|
222
|
+
- Related issues (if any)
|
|
223
|
+
6. **Respond to feedback**:
|
|
224
|
+
|
|
225
|
+
- Address any review comments
|
|
226
|
+
- Make requested changes
|
|
227
|
+
- Keep the PR up to date with `main`
|
|
228
|
+
|
|
229
|
+
### Pull Request Guidelines
|
|
230
|
+
|
|
231
|
+
- Keep PRs focused and reasonably sized
|
|
232
|
+
- One feature or fix per PR
|
|
233
|
+
- Include a clear description
|
|
234
|
+
- Reference related issues
|
|
235
|
+
- Ensure all CI checks pass
|
|
236
|
+
- Request review when ready
|
|
237
|
+
|
|
238
|
+
## Reporting Bugs
|
|
239
|
+
|
|
240
|
+
When reporting bugs, please include:
|
|
241
|
+
|
|
242
|
+
1. **Description**: Clear description of the issue
|
|
243
|
+
2. **Steps to Reproduce**: Detailed steps to reproduce the bug
|
|
244
|
+
3. **Expected Behavior**: What you expected to happen
|
|
245
|
+
4. **Actual Behavior**: What actually happened
|
|
246
|
+
5. **Environment**:
|
|
247
|
+
- React Native version
|
|
248
|
+
- Expo SDK version
|
|
249
|
+
- iOS/Android version
|
|
250
|
+
- Device or simulator information
|
|
251
|
+
6. **Screenshots/Videos**: If applicable
|
|
252
|
+
7. **Code Sample**: Minimal code example that reproduces the issue
|
|
253
|
+
|
|
254
|
+
## Requesting Features
|
|
255
|
+
|
|
256
|
+
When requesting features, please include:
|
|
257
|
+
|
|
258
|
+
1. **Use Case**: Why this feature would be useful
|
|
259
|
+
2. **Proposed Solution**: How you envision it working
|
|
260
|
+
3. **Alternatives**: Any alternative solutions you've considered
|
|
261
|
+
4. **Additional Context**: Any other relevant information
|
|
262
|
+
|
|
263
|
+
## Questions?
|
|
264
|
+
|
|
265
|
+
Feel free to:
|
|
266
|
+
|
|
267
|
+
- Open an issue for questions or discussions
|
|
268
|
+
- Start a discussion in the GitHub Discussions tab
|
|
269
|
+
- Contact the maintainer directly
|
|
270
|
+
|
|
271
|
+
Thank you for contributing to `@kishannareshpal/expo-pdf`! 🎉
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kishan Jadav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# `@kishannareshpal/expo-pdf`
|
|
2
|
+
|
|
3
|
+
A cross-platform, high-performance PDF viewer for React Native and Expo, built on top of native PDF rendering engines.
|
|
4
|
+
|
|
5
|
+
### Core features
|
|
6
|
+
|
|
7
|
+
- [X] Supports Android and iOS
|
|
8
|
+
- Uses Apple's [`PDFKit`](https://developer.apple.com/documentation/pdfkit/pdfview) on iOS
|
|
9
|
+
- Uses [kishannareshpal/AndroidPdfViewer](https://github.com/kishannareshpal/AndroidPdfViewer) on Android which is a maintained
|
|
10
|
+
fork of [barteksc/AndroidPdfViewerV2](https://github.com/kishannareshpal/AndroidPdfViewer) which uses the open-source [PDFium](https://pdfium.googlesource.com/pdfium/+/HEAD/docs/getting-started.md) PDF rendering engine.
|
|
11
|
+
- Note: We'll be looking to switch to [`androidx.pdf`](https://developer.android.com/jetpack/androidx/releases/pdf) on Android once that becomes stable.
|
|
12
|
+
- [x] Load PDFs from remote URLs or local file paths
|
|
13
|
+
- [x] Supports local file URIs on android and iOS and ContentResolver URIs on android.
|
|
14
|
+
- [x] Remote URLs cannot be passed directly to the PdfView component. You must download it and then use the local file URI to preview.
|
|
15
|
+
- [X] Pinch-to-zoom / double-tap-to-zoom and drag gestures
|
|
16
|
+
- [x] Support for password-protected PDFs
|
|
17
|
+
- [x] Horizontal and vertical reading modes
|
|
18
|
+
- [x] Support for content-insets
|
|
19
|
+
|
|
20
|
+
### Demo
|
|
21
|
+
|
|
22
|
+
| [iOS](./docs/demo-ios.mp4) | [Android](./docs/demo-android.mp4) |
|
|
23
|
+
| ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
24
|
+
| <video src="https://github.com/user-attachments/assets/6c88deb7-7801-4e3a-b93e-88f9688435a1" /> | <video src="https://github.com/user-attachments/assets/ce9bd00f-0a4e-47ec-800c-cbdcba5c5554" /> |
|
|
25
|
+
|
|
26
|
+
### Installation
|
|
27
|
+
|
|
28
|
+
This package works with both Expo and framework-less React Native projects but Expo provides a more streamlined experience.
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
npm install @kishannareshpal/expo-pdf
|
|
32
|
+
|
|
33
|
+
# bun add @kishannareshpal/expo-pdf
|
|
34
|
+
# pnpm add @kishannareshpal/expo-pdf
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Usage
|
|
38
|
+
|
|
39
|
+
#### Use a locally bundled PDF
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
import { PdfView } from '@kishannareshpal/expo-pdf'
|
|
43
|
+
|
|
44
|
+
export const App = () => {
|
|
45
|
+
const [assets] = useAssets([require('./assets/sample.pdf')]);
|
|
46
|
+
const [uri, setUri] = useState<string | null>(null);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!assets?.length) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
assets[0].downloadAsync()
|
|
54
|
+
.then((asset) => setUri(asset.localUri))
|
|
55
|
+
.catch(console.error)
|
|
56
|
+
}, [assets])
|
|
57
|
+
|
|
58
|
+
if (!uri) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<PdfView
|
|
64
|
+
style={{ flex: 1 }}
|
|
65
|
+
uri={uri}
|
|
66
|
+
/>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### Load a file picked using a system picker
|
|
72
|
+
|
|
73
|
+
```jsx
|
|
74
|
+
import { File } from 'expo-file-system';
|
|
75
|
+
import * as DocumentPicker from 'expo-document-picker';
|
|
76
|
+
import { PdfView } from '@kishannareshpal/expo-pdf'
|
|
77
|
+
|
|
78
|
+
export const App = () => {
|
|
79
|
+
const [uri, setUri] = useState<string | null>(null)
|
|
80
|
+
|
|
81
|
+
const pickFile = () => {
|
|
82
|
+
try {
|
|
83
|
+
const result = await DocumentPicker.getDocumentAsync({ copyToCacheDirectory: true });
|
|
84
|
+
const file = new File(result.assets[0]);
|
|
85
|
+
setUri(file.localUri)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!uri) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<View>
|
|
97
|
+
<Button onPress={pickFile}>Pick a file</Button>
|
|
98
|
+
|
|
99
|
+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
100
|
+
{uri ? (
|
|
101
|
+
<PdfView
|
|
102
|
+
style={{ flex: 1 }}
|
|
103
|
+
uri={uri}
|
|
104
|
+
/>
|
|
105
|
+
) : (
|
|
106
|
+
<Text>Please pick a file<Text>
|
|
107
|
+
)}
|
|
108
|
+
</View>
|
|
109
|
+
</View>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Use remote URLs
|
|
115
|
+
|
|
116
|
+
```jsx
|
|
117
|
+
import { File } from 'expo-file-system';
|
|
118
|
+
import * as DocumentPicker from 'expo-document-picker';
|
|
119
|
+
import { PdfView } from '@kishannareshpal/expo-pdf'
|
|
120
|
+
|
|
121
|
+
export const App = () => {
|
|
122
|
+
const [uri, setUri] = useState<string | null>(null)
|
|
123
|
+
|
|
124
|
+
const loadFromUrl = (url: string) => {
|
|
125
|
+
const destination = new Directory(Paths.cache, 'pdfs');
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
destination.create();
|
|
129
|
+
const output = await File.downloadFileAsync(url, destination);
|
|
130
|
+
setUri(output.uri)
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!uri) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<View>
|
|
142
|
+
<Button onPress={() => loadFromUrl("https://pdfobject.com/pdf/sample.pdf")}>
|
|
143
|
+
Download and load from URL
|
|
144
|
+
</Button>
|
|
145
|
+
|
|
146
|
+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
147
|
+
{uri ? (
|
|
148
|
+
<PdfView
|
|
149
|
+
style={{ flex: 1 }}
|
|
150
|
+
uri={uri}
|
|
151
|
+
/>
|
|
152
|
+
) : (
|
|
153
|
+
<Text>Please download the file to preview<Text>
|
|
154
|
+
)}
|
|
155
|
+
</View>
|
|
156
|
+
</View>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### API
|
|
162
|
+
|
|
163
|
+
| Props | Required | Type | Description | Default |
|
|
164
|
+
| ------------------------ | -------- | --------------------------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------ |
|
|
165
|
+
| `uri` | Required | `string` | PDF document URL or local file path. | - |
|
|
166
|
+
| `password` | No | `string` | PDF document URL or local file path. | `undefined` |
|
|
167
|
+
| `pagingEnabled` | No | `boolean` | PDF document URL or local file path. | `false` |
|
|
168
|
+
| `disableDoubleTapToZoom` | No | `boolean` | PDF document URL or local file path. | `false` |
|
|
169
|
+
| `horizontal` | No | `boolean` | PDF document URL or local file path. | `false` |
|
|
170
|
+
| `pageGap` | No | `number` | PDF document URL or local file path. | `0` |
|
|
171
|
+
| `contentPadding` | No | [`ContentPadding`](#contentpadding) | PDF document URL or local file path. | `{ top: 0, left: 0, right: 0, bottom: 0 }` |
|
|
172
|
+
| `fitMode` | No | [`FitMode`](#fitmode) | PDF document URL or local file path. | `"width"` |
|
|
173
|
+
| `onLoadComplete` | No | [`(OnLoadCompleteEventPayload) => void`](#onloadcompleteeventpayload) | Triggered once the document has been fully loaded. | - |
|
|
174
|
+
| `onPageChanged` | No | [`(OnPageChangedPayload) => void`](#onpagechangedeventpayload) | Triggered when the user navigates to a different page. | - |
|
|
175
|
+
| `onError` | No | [`(OnErrorPayload) => void`](#onerroreventpayload) | Triggered when the PDF fails to load or render. | - |
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
#### API Reference
|
|
179
|
+
|
|
180
|
+
##### `ContentPadding`
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
{ top?: number, left?: number, right?: number, bottom?: number }
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
##### `FitMode`
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
"width" | "height" | "both"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
##### `OnLoadCompleteEventPayload`
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
{ pageCount: number }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
##### `OnPageChangedEventPayload`
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
{ pageIndex: number, pageCount: number }
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
##### `OnErrorEventPayload`
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
{
|
|
208
|
+
code: 'invalid_url' | 'invalid_document' | 'password_required' | 'password_incorrect',
|
|
209
|
+
message: string
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Contributing
|
|
214
|
+
|
|
215
|
+
Contributions are welcome!
|
|
216
|
+
|
|
217
|
+
#### How to contribute
|
|
218
|
+
|
|
219
|
+
Please read [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
220
|
+
|
|
221
|
+
#### Publishing a new version to the registry
|
|
222
|
+
|
|
223
|
+
> [!NOTE]
|
|
224
|
+
>
|
|
225
|
+
> This package follows semantic versioning with the format: `major.minor.patch`.
|
|
226
|
+
> - Major version: Increment when making incompatible API changes.
|
|
227
|
+
> - Minor version: Increment when adding new functionality in a backward-compatible way.
|
|
228
|
+
> - Patch version: Increment when fixing bugs in a backward-compatible manner.
|
|
229
|
+
****
|
|
230
|
+
1. Bump `package.json` version using one of `npm version patch|minor|major` - this will create a new `tag`.
|
|
231
|
+
2. `git push --tags` to push the new changes including the newly created tag.
|
|
232
|
+
3. Navigate to [Create a New Release](https://github.com/kishannareshpal/expo-pdf/releases/new)
|
|
233
|
+
4. Select the latest tag you've created above.
|
|
234
|
+
5. Use the same name as the tag for the release title.
|
|
235
|
+
6. Click <kbd>Generate release notes</kbd>, and/or edit the description to detail the changes.
|
|
236
|
+
7. Click the green <kbd>Publish release</kbd> button.
|
|
237
|
+
8. A GitHub action will automatically run to publish the new version of the package to the registry.
|
|
238
|
+
- Monitor the status at [kishannareshpal/expo-pdf/actions](https://github.com/kishannareshpal/expo-pdf/actions)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
### License
|
|
242
|
+
|
|
243
|
+
MIT
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
group = 'com.kishannareshpal.expopdf'
|
|
4
|
+
version = '0.1.0'
|
|
5
|
+
|
|
6
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useExpoPublishing()
|
|
11
|
+
|
|
12
|
+
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
|
13
|
+
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
|
|
14
|
+
// Most of the time, you may like to manage the Android SDK versions yourself.
|
|
15
|
+
def useManagedAndroidSdkVersions = false
|
|
16
|
+
if (useManagedAndroidSdkVersions) {
|
|
17
|
+
useDefaultAndroidSdkVersions()
|
|
18
|
+
} else {
|
|
19
|
+
buildscript {
|
|
20
|
+
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
+
ext.safeExtGet = { prop, fallback ->
|
|
22
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
project.android {
|
|
26
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 36)
|
|
27
|
+
defaultConfig {
|
|
28
|
+
minSdkVersion safeExtGet("minSdkVersion", 24)
|
|
29
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 36)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
android {
|
|
35
|
+
namespace "com.kishannareshpal.expopdf"
|
|
36
|
+
defaultConfig {
|
|
37
|
+
versionCode 1
|
|
38
|
+
versionName "0.1.0"
|
|
39
|
+
}
|
|
40
|
+
lintOptions {
|
|
41
|
+
abortOnError false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
dependencies {
|
|
46
|
+
// NOTE: The original repo at com.github.barteksc is abandoned by the maintainer; there will be no
|
|
47
|
+
// more updates coming from that repo.
|
|
48
|
+
// - com.github.kishannareshpal:AndroidPdfViewer repo is based on PdfiumAndroidKt, a much newer
|
|
49
|
+
// fork of PdfiumAndroid, with better maintenance and updated native libraries.
|
|
50
|
+
implementation 'com.github.kishannareshpal:AndroidPdfViewer:2026.01.05.5'
|
|
51
|
+
|
|
52
|
+
// Explicitly define the version of PdfiumAndroidKt so this can be updated independently of
|
|
53
|
+
// AndroidPdfViewer as updates are provided.
|
|
54
|
+
implementation 'io.legere:pdfiumandroid:1.0.35'
|
|
55
|
+
}
|