├── .editorconfig ├── .eslintignore ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md ├── actions │ └── setup │ │ └── action.yml └── workflows │ └── ci.yml ├── .gitignore ├── .nvmrc ├── .watchmanconfig ├── .yarnrc ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── imagespdf │ ├── CreatePdfOptions.java │ ├── ImageFit.java │ ├── ImageScaling.java │ ├── ImagesPdfModule.java │ └── ImagesPdfPackage.java ├── babel.config.js ├── docs ├── example-android.gif └── example-ios.gif ├── example ├── .bundle │ └── config ├── .node-version ├── .ruby-version ├── .watchmanconfig ├── Gemfile ├── Gemfile.lock ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── imagespdfexample │ │ │ │ └── ReactNativeFlipper.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── imagespdfexample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── release │ │ │ └── java │ │ │ └── com │ │ │ └── imagespdfexample │ │ │ └── ReactNativeFlipper.java │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── .ruby-version │ ├── .xcode.env │ ├── File.swift │ ├── ImagesPdfExample-Bridging-Header.h │ ├── ImagesPdfExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── ImagesPdfExample.xcscheme │ ├── ImagesPdfExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── ImagesPdfExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── main.m │ ├── ImagesPdfExampleTests │ │ ├── ImagesPdfExampleTests.m │ │ └── Info.plist │ ├── Podfile │ └── Podfile.lock ├── metro.config.js ├── package.json ├── react-native.config.js ├── src │ └── App.tsx └── yarn.lock ├── ios ├── CreatePdfError.swift ├── CreatePdfOptions.swift ├── ImagesPdf-Bridging-Header.h ├── ImagesPdf.m ├── ImagesPdf.swift ├── ImagesPdf.xcodeproj │ └── project.pbxproj └── UIImage+Scaling.swift ├── lefthook.yml ├── lib ├── commonjs │ ├── index.js │ └── index.js.map ├── module │ ├── index.js │ └── index.js.map └── typescript │ ├── __tests__ │ ├── index.test.d.ts │ └── index.test.d.ts.map │ ├── index.d.ts │ └── index.d.ts.map ├── package.json ├── react-native-images-to-pdf.podspec ├── scripts └── bootstrap.js ├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── tsconfig.build.json ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve. 4 | title: '' 5 | labels: bug, question 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Summary 11 | 12 | 15 | 16 | ## Reproducible repository 17 | 18 | 24 | 25 | ## Steps to reproduce 26 | 27 | 30 | 31 | 1. … 32 | 2. … 33 | 34 | Describe what you expected to happen: 35 | 36 | 1. … 37 | 2. … 38 | 39 | ## Environment info 40 | 41 | 44 | 45 | `npx react-native info` output: 46 | 47 | ```bash 48 | # paste it here 49 | ``` 50 | 51 | library version: x.x.x 52 | 53 | iOS / Android version: x.x 54 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Use this if there is something not clear about the code or its docs. 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | # Question 11 | 12 | If you're asking a question, please use [discussions](https://github.com/Canciller/react-native-images-to-pdf/discussions). 13 | The issue template is reserved for bugs and feature requests only. Thank you. 14 | -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | description: Setup Node.js and install dependencies 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Setup Node.js 8 | uses: actions/setup-node@v3 9 | with: 10 | node-version-file: .nvmrc 11 | 12 | - name: Cache dependencies 13 | id: yarn-cache 14 | uses: actions/cache@v3 15 | with: 16 | path: | 17 | **/node_modules 18 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 19 | restore-keys: | 20 | ${{ runner.os }}-yarn- 21 | 22 | - name: Install dependencies 23 | if: steps.yarn-cache.outputs.cache-hit != 'true' 24 | run: | 25 | yarn install --cwd example --frozen-lockfile 26 | yarn install --frozen-lockfile 27 | shell: bash 28 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | lint: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v3 16 | 17 | - name: Setup 18 | uses: ./.github/actions/setup 19 | 20 | - name: Lint files 21 | run: yarn lint 22 | 23 | - name: Typecheck files 24 | run: yarn typecheck 25 | 26 | test: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v3 31 | 32 | - name: Setup 33 | uses: ./.github/actions/setup 34 | 35 | - name: Run unit tests 36 | run: yarn test --maxWorkers=2 --coverage 37 | 38 | build: 39 | runs-on: ubuntu-latest 40 | steps: 41 | - name: Checkout 42 | uses: actions/checkout@v3 43 | 44 | - name: Setup 45 | uses: ./.github/actions/setup 46 | 47 | - name: Build package 48 | run: yarn prepack 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # Ruby 48 | example/vendor/ 49 | 50 | # node.js 51 | # 52 | node_modules/ 53 | npm-debug.log 54 | yarn-debug.log 55 | yarn-error.log 56 | 57 | # BUCK 58 | buck-out/ 59 | \.buckd/ 60 | android/app/libs 61 | android/keystores/debug.keystore 62 | 63 | # Expo 64 | .expo/ 65 | 66 | # Turborepo 67 | .turbo/ 68 | 69 | # Watchman 70 | .watchman-cookie* 71 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 16.18.1 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [INSERT CONTACT METHOD]. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are always welcome, no matter how large or small! 4 | 5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md). 6 | 7 | ## Development workflow 8 | 9 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 10 | 11 | ```sh 12 | yarn 13 | ``` 14 | 15 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 16 | 17 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 18 | 19 | To start the packager: 20 | 21 | ```sh 22 | yarn example start 23 | ``` 24 | 25 | To run the example app on Android: 26 | 27 | ```sh 28 | yarn example android 29 | ``` 30 | 31 | To run the example app on iOS: 32 | 33 | ```sh 34 | yarn example ios 35 | ``` 36 | 37 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 38 | 39 | ```sh 40 | yarn typecheck 41 | yarn lint 42 | ``` 43 | 44 | To fix formatting errors, run the following: 45 | 46 | ```sh 47 | yarn lint --fix 48 | ``` 49 | 50 | Remember to add tests for your change if possible. Run the unit tests by: 51 | 52 | ```sh 53 | yarn test 54 | ``` 55 | 56 | To edit the Objective-C or Swift files, open `example/ios/ImagesPdfExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-images-to-pdf`. 57 | 58 | To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-images-to-pdf` under `Android`. 59 | 60 | 61 | ### Commit message convention 62 | 63 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 64 | 65 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 66 | - `feat`: new features, e.g. add new method to the module. 67 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 68 | - `docs`: changes into documentation, e.g. add usage example for the module.. 69 | - `test`: adding or updating tests, e.g. add integration tests using detox. 70 | - `chore`: tooling changes, e.g. change CI config. 71 | 72 | Our pre-commit hooks verify that your commit message matches this format when committing. 73 | 74 | ### Linting and tests 75 | 76 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 77 | 78 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 79 | 80 | Our pre-commit hooks verify that the linter and tests pass when committing. 81 | 82 | ### Publishing to npm 83 | 84 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 85 | 86 | To publish new versions, run the following: 87 | 88 | ```sh 89 | yarn release 90 | ``` 91 | 92 | ### Scripts 93 | 94 | The `package.json` file contains various scripts for common tasks: 95 | 96 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 97 | - `yarn typecheck`: type-check files with TypeScript. 98 | - `yarn lint`: lint files with ESLint. 99 | - `yarn test`: run unit tests with Jest. 100 | - `yarn example start`: start the Metro server for the example app. 101 | - `yarn example android`: run the example app on Android. 102 | - `yarn example ios`: run the example app on iOS. 103 | 104 | ### Sending a pull request 105 | 106 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 107 | 108 | When you're sending a pull request: 109 | 110 | - Prefer small pull requests focused on one change. 111 | - Verify that linters and tests are passing. 112 | - Review the documentation to make sure it looks good. 113 | - Follow the pull request template when opening a pull request. 114 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 115 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 canciller 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-images-to-pdf 2 | 3 | [![badge](https://img.shields.io/npm/v/react-native-images-to-pdf.svg?style=flat-square)](https://www.npmjs.com/package/react-native-images-to-pdf) 4 | 5 | Easily generate PDF files from images in React Native. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
iOSAndroid

14 | 15 | ## Installation 16 | 17 | ```sh 18 | npm install react-native-images-to-pdf 19 | ``` 20 | 21 | or 22 | 23 | ```sh 24 | yarn add react-native-images-to-pdf 25 | ``` 26 | 27 | ### iOS 28 | 29 | Run `pod install` in the `ios` directory. 30 | 31 | ## Usage 32 | 33 | ### Example using [`react-native-blob-util`](https://github.com/RonRadtke/react-native-blob-util) 34 | 35 | ```javascript 36 | import { createPdf } from 'react-native-images-to-pdf'; 37 | import RNBlobUtil from 'react-native-blob-util'; 38 | 39 | const options = { 40 | pages: [ 41 | { imagePath: '/path/to/image1.jpg' }, 42 | { imagePath: '/path/to/image2.jpg' } 43 | ], 44 | outputPath: `file://${RNBlobUtil.fs.dirs.DocumentDir}/file.pdf`, 45 | }; 46 | 47 | createPdf(options) 48 | .then((path) => console.log(`PDF created successfully: ${path}`)) 49 | .catch((error) => console.log(`Failed to create PDF: ${error}`)); 50 | ``` 51 | 52 | This example is using [`react-native-blob-util`](https://github.com/RonRadtke/react-native-blob-util) to get a valid `outputPath`, but you can choose any other library to achieve the same functionality. 53 | 54 | ### Example using [`react-native-document-scanner-plugin`](https://github.com/websitebeaver/react-native-document-scanner-plugin) 55 | 56 | ```javascript 57 | import { createPdf } from 'react-native-images-to-pdf'; 58 | import DocumentScanner from 'react-native-document-scanner-plugin'; 59 | 60 | DocumentScanner.scanDocument() 61 | .then(({scannedImages}) => { 62 | if (!scannedImages?.length) { 63 | throw new Error('No images scanned'); 64 | } 65 | 66 | return createPdf({ 67 | pages: scannedImages.map(imagePath => ({ imagePath })), 68 | outputPath: `file:///path/to/output/file.pdf`, 69 | }); 70 | }) 71 | .then(path => console.log(`PDF created successfully: ${path}`)) 72 | .catch(error => console.log(`Failed to create PDF: ${error}`)); 73 | ``` 74 | 75 | ## API 76 | 77 | ### `createPdf(options: CreatePdfOptions) => Promise` 78 | 79 | Returns a Promise that resolves to a `string` representing the output path of the generated PDF file. 80 | 81 | #### `CreatePdfOptions` 82 | 83 | | Property | Type | Description | 84 | | ------------ | ----------------------- | ----------------------------------------- | 85 | | `pages` | `Page[]` | Pages that should be included in the PDF. | 86 | | `outputPath` | `string` | The path to the output PDF file. | 87 | 88 | #### Valid `outputPath` 89 | 90 | | Usage | Description | iOS | Android | 91 | | ---------------------------------- | ------------------------------ | --- | ------- | 92 | | `file:///absolute/path/to/xxx.pdf` | Save PDF to local file system. | ✓ | ✓ | 93 | 94 | ### `Page` 95 | 96 | | Property | Type | Required | Default | Description | 97 | | ----------------- | ---------- | -------- | ------------ | ---------------------------------------------------------------------------------- | 98 | | `imagePath` | `string` | ✓ | | Path to the image file. | 99 | | `imageFit` | `ImageFit` | | `'none'` | Image fitting option. Possible values: `'none'`, `'fill'`, `'contain'`, `'cover'`. | 100 | | `width` | `number` | | Image width | Width of the page in pixels. | 101 | | `height` | `number` | | Image height | Height of the page in pixels. | 102 | | `backgroundColor` | `string` | | `'white'` | Background color of the page. | 103 | 104 | #### Valid `imagePath` 105 | 106 | | Usage | Description | iOS | Android | 107 | | ------------------------------------ | ---------------------------------- | --- | ------- | 108 | | `file:///absolute/path/to/image.xxx` | Load image from local file system. | ✓ | ✓ | 109 | | `data:image/xxx;base64,iVBORw...` | Load image from base64 string. | ✓ | ✓ | 110 | 111 | ## Example 112 | 113 | Check the `example` folder for a usage demo. 114 | 115 | ## Contributing 116 | 117 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 118 | 119 | ## License 120 | 121 | MIT 122 | 123 | --- 124 | 125 | Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) 126 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | classpath "com.android.tools.build:gradle:7.2.1" 9 | } 10 | } 11 | 12 | def isNewArchitectureEnabled() { 13 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" 14 | } 15 | 16 | apply plugin: "com.android.library" 17 | 18 | 19 | def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') } 20 | 21 | if (isNewArchitectureEnabled()) { 22 | apply plugin: "com.facebook.react" 23 | } 24 | 25 | def getExtOrDefault(name) { 26 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ImagesPdf_" + name] 27 | } 28 | 29 | def getExtOrIntegerDefault(name) { 30 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ImagesPdf_" + name]).toInteger() 31 | } 32 | 33 | android { 34 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") 35 | 36 | defaultConfig { 37 | minSdkVersion getExtOrIntegerDefault("minSdkVersion") 38 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") 39 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 40 | } 41 | buildTypes { 42 | release { 43 | minifyEnabled false 44 | } 45 | } 46 | 47 | lintOptions { 48 | disable "GradleCompatible" 49 | } 50 | 51 | compileOptions { 52 | sourceCompatibility JavaVersion.VERSION_1_8 53 | targetCompatibility JavaVersion.VERSION_1_8 54 | } 55 | 56 | } 57 | 58 | repositories { 59 | mavenCentral() 60 | google() 61 | } 62 | 63 | 64 | dependencies { 65 | // For < 0.71, this will be from the local maven repo 66 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin 67 | //noinspection GradleDynamicVersion 68 | implementation "com.facebook.react:react-native:+" 69 | implementation 'androidx.documentfile:documentfile:1.0.1' 70 | implementation "com.google.guava:guava:32.1.2-android" 71 | } 72 | 73 | if (isNewArchitectureEnabled()) { 74 | react { 75 | jsRootDir = file("../src/") 76 | libraryName = "ImagesPdf" 77 | codegenJavaPackageName = "com.imagespdf" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | ImagesPdf_kotlinVersion=1.7.0 2 | ImagesPdf_minSdkVersion=21 3 | ImagesPdf_targetSdkVersion=31 4 | ImagesPdf_compileSdkVersion=31 5 | ImagesPdf_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/imagespdf/CreatePdfOptions.java: -------------------------------------------------------------------------------- 1 | package com.imagespdf; 2 | 3 | import com.facebook.react.bridge.ReadableArray; 4 | import com.facebook.react.bridge.ReadableMap; 5 | 6 | public class CreatePdfOptions { 7 | public String outputPath; 8 | public Page[] pages; 9 | 10 | public CreatePdfOptions(ReadableMap options) { 11 | outputPath = getStringOrThrow(options, "outputPath"); 12 | pages = parsePages(getArrayOrThrow(options, "pages")); 13 | } 14 | 15 | private String getStringOrThrow(ReadableMap options, String key) { 16 | if (!options.hasKey(key)) { 17 | throw new IllegalArgumentException("Required option '" + key + "' not found."); 18 | } 19 | return options.getString(key); 20 | } 21 | 22 | private ReadableArray getArrayOrThrow(ReadableMap options, String key) { 23 | if (!options.hasKey(key)) { 24 | throw new IllegalArgumentException("Required option '" + key + "' not found."); 25 | } 26 | return options.getArray(key); 27 | } 28 | 29 | private Integer getInt(ReadableMap options, String key) { 30 | if(options.hasKey(key)) { 31 | return options.getInt(key); 32 | } 33 | 34 | return null; 35 | } 36 | 37 | private Page[] parsePages(ReadableArray pagesArray) { 38 | if (pagesArray == null) { 39 | throw new IllegalArgumentException("Invalid 'pages' argument. 'pages' cannot be null."); 40 | } 41 | 42 | Page[] parsedPages = new Page[pagesArray.size()]; 43 | for (int i = 0; i < pagesArray.size(); i++) { 44 | ReadableMap pageMap = pagesArray.getMap(i); 45 | String imagePath = pageMap.getString("imagePath"); 46 | Integer width = getInt(pageMap, "width"); 47 | Integer height = getInt(pageMap, "height"); 48 | Integer backgroundColor = getInt(pageMap, "backgroundColor"); 49 | 50 | ImageFit imageFit = parseImageFit(pageMap.getString("imageFit")); 51 | 52 | parsedPages[i] = new Page(imagePath, imageFit, width, height, backgroundColor); 53 | } 54 | 55 | return parsedPages; 56 | } 57 | 58 | private ImageFit parseImageFit(String imageFitValue) { 59 | try { 60 | return imageFitValue == null ? ImageFit.NONE : ImageFit.valueOf(imageFitValue.toUpperCase()); 61 | } catch (IllegalArgumentException e) { 62 | throw new IllegalArgumentException("Invalid 'imageFit' value: " + imageFitValue); 63 | } 64 | } 65 | 66 | public static class Page { 67 | public String imagePath; 68 | public ImageFit imageFit; 69 | public Integer width; 70 | public Integer height; 71 | public Integer backgroundColor; 72 | 73 | public Page(String imagePath, 74 | ImageFit imageFit, 75 | Integer width, 76 | Integer height, 77 | Integer backgroundColor) { 78 | this.imagePath = imagePath; 79 | this.imageFit = imageFit; 80 | this.width = width; 81 | this.height = height; 82 | this.backgroundColor = backgroundColor; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /android/src/main/java/com/imagespdf/ImageFit.java: -------------------------------------------------------------------------------- 1 | package com.imagespdf; 2 | 3 | public enum ImageFit { 4 | NONE, 5 | FILL, 6 | COVER, 7 | CONTAIN 8 | } 9 | -------------------------------------------------------------------------------- /android/src/main/java/com/imagespdf/ImageScaling.java: -------------------------------------------------------------------------------- 1 | package com.imagespdf; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Canvas; 5 | import android.graphics.Matrix; 6 | import android.graphics.Paint; 7 | import android.graphics.Point; 8 | 9 | // TODO: ImagePosition 10 | 11 | public class ImageScaling { 12 | public static Bitmap scale(Bitmap image, Point size, ImageFit fit) throws Exception { 13 | switch (fit) { 14 | case NONE: 15 | return scaleWithNone(image, size); 16 | case CONTAIN: 17 | return scaleWithContain(image, size); 18 | case COVER: 19 | return scaleWithCover(image, size); 20 | case FILL: 21 | return scaleWithFill(image, size); 22 | default: 23 | throw new Exception("Unknown scale fit: " + fit); 24 | } 25 | } 26 | 27 | private static Bitmap scaleWithNone(Bitmap bitmap, Point size) { 28 | // Create background bitmap. 29 | 30 | Bitmap newBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); 31 | Canvas canvas = new Canvas(newBitmap); 32 | 33 | // Calculate new width and height. 34 | 35 | int scaledWidth = bitmap.getWidth(); 36 | int scaledHeight = bitmap.getHeight(); 37 | 38 | // Apply transformations. 39 | 40 | Matrix matrix = new Matrix(); 41 | 42 | float translateX = (size.x - scaledWidth) / 2f; 43 | float translateY = (size.y - scaledHeight) / 2f; 44 | 45 | matrix.postTranslate(translateX, translateY); 46 | 47 | // Draw the bitmap. 48 | 49 | Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 50 | 51 | canvas.drawBitmap(bitmap, matrix, paint); 52 | 53 | return newBitmap; 54 | } 55 | 56 | private static Bitmap scaleWithContain(Bitmap bitmap, Point size) { 57 | // Create background bitmap. 58 | 59 | Bitmap newBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); 60 | Canvas canvas = new Canvas(newBitmap); 61 | 62 | // Calculate new width and height. 63 | 64 | int width = bitmap.getWidth(); 65 | int height = bitmap.getHeight(); 66 | 67 | float aspectRatio = (float) width / height; 68 | float targetAspectRatio = (float) size.x / size.y; 69 | 70 | int scaledWidth, scaledHeight; 71 | if (aspectRatio > targetAspectRatio) { 72 | scaledWidth = size.x; 73 | scaledHeight = (int) (size.x / aspectRatio); 74 | } else { 75 | scaledWidth = (int) (size.y * aspectRatio); 76 | scaledHeight = size.y; 77 | } 78 | 79 | // Apply transformations. 80 | 81 | Matrix matrix = new Matrix(); 82 | 83 | float scaleX = (float) scaledWidth / width; 84 | float scaleY = (float) scaledHeight / height; 85 | 86 | matrix.postScale(scaleX, scaleY); 87 | 88 | float translateX = (size.x - scaledWidth) / 2f; 89 | float translateY = (size.y - scaledHeight) / 2f; 90 | 91 | matrix.postTranslate(translateX, translateY); 92 | 93 | // Draw the bitmap. 94 | 95 | Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 96 | 97 | canvas.drawBitmap(bitmap, matrix, paint); 98 | 99 | return newBitmap; 100 | } 101 | 102 | private static Bitmap scaleWithCover(Bitmap bitmap, Point size) { 103 | // Create background bitmap. 104 | 105 | Bitmap newBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); 106 | Canvas canvas = new Canvas(newBitmap); 107 | 108 | // Calculate new width and height. 109 | 110 | int width = bitmap.getWidth(); 111 | int height = bitmap.getHeight(); 112 | 113 | float aspectRatio = (float) width / height; 114 | float targetAspectRatio = (float) size.x / size.y; 115 | 116 | float scaleFactor; 117 | if (aspectRatio > targetAspectRatio) { 118 | scaleFactor = (float) size.y / height; 119 | } else { 120 | scaleFactor = (float) size.x / width; 121 | } 122 | 123 | int scaledWidth = Math.round(width * scaleFactor); 124 | int scaledHeight = Math.round(height * scaleFactor); 125 | 126 | // Apply transformations. 127 | 128 | Matrix matrix = new Matrix(); 129 | 130 | matrix.postScale(scaleFactor, scaleFactor); 131 | 132 | float translateX = (size.x - scaledWidth) / 2f; 133 | float translateY = (size.y - scaledHeight) / 2f; 134 | 135 | matrix.postTranslate(translateX, translateY); 136 | 137 | // Draw the bitmap. 138 | 139 | Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 140 | 141 | canvas.drawBitmap(bitmap, matrix, paint); 142 | 143 | return newBitmap; 144 | } 145 | 146 | private static Bitmap scaleWithFill(Bitmap bitmap, Point size) { 147 | // Create background bitmap. 148 | 149 | Bitmap newBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); 150 | Canvas canvas = new Canvas(newBitmap); 151 | 152 | // Calculate new width and height. 153 | 154 | int width = bitmap.getWidth(); 155 | int height = bitmap.getHeight(); 156 | 157 | int scaledWidth = size.x; 158 | int scaledHeight = size.y; 159 | 160 | // Apply transformations. 161 | 162 | Matrix matrix = new Matrix(); 163 | 164 | float scaleX = (float) scaledWidth / width; 165 | float scaleY = (float) scaledHeight / height; 166 | 167 | matrix.postScale(scaleX, scaleY); 168 | 169 | // Draw the bitmap. 170 | 171 | Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); 172 | 173 | canvas.drawBitmap(bitmap, matrix, paint); 174 | 175 | return newBitmap; 176 | } 177 | } 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /android/src/main/java/com/imagespdf/ImagesPdfModule.java: -------------------------------------------------------------------------------- 1 | package com.imagespdf; 2 | 3 | import android.content.ContentResolver; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Point; 8 | import android.graphics.pdf.PdfDocument; 9 | import android.net.Uri; 10 | import android.util.Log; 11 | 12 | import androidx.annotation.NonNull; 13 | 14 | import com.facebook.react.bridge.Promise; 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 17 | import com.facebook.react.bridge.ReactMethod; 18 | import com.facebook.react.bridge.ReadableMap; 19 | import com.facebook.react.module.annotations.ReactModule; 20 | import com.google.common.io.BaseEncoding; 21 | 22 | import java.io.FileInputStream; 23 | import java.io.FileOutputStream; 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | 28 | @ReactModule(name = ImagesPdfModule.NAME) 29 | public class ImagesPdfModule extends ReactContextBaseJavaModule { 30 | public static final String NAME = "ImagesPdf"; 31 | 32 | public ImagesPdfModule(ReactApplicationContext reactContext) { 33 | super(reactContext); 34 | } 35 | 36 | @Override 37 | @NonNull 38 | public String getName() { 39 | return NAME; 40 | } 41 | 42 | static final String MIME_TYPE_PDF = "application/pdf"; 43 | 44 | @ReactMethod 45 | public void createPdf(ReadableMap optionsMap, Promise promise) { 46 | try { 47 | CreatePdfOptions options = new CreatePdfOptions(optionsMap); 48 | 49 | String outputPath = options.outputPath; 50 | CreatePdfOptions.Page[] pages = options.pages; 51 | 52 | if (pages.length == 0) { 53 | throw new Exception("No images provided."); 54 | } 55 | 56 | PdfDocument pdfDocument = new PdfDocument(); 57 | 58 | try { 59 | for (int i = 0; i < pages.length; ++i) { 60 | CreatePdfOptions.Page config = pages[i]; 61 | String imagePath = config.imagePath; 62 | 63 | Bitmap image = getBitmapFromPathOrUri(imagePath); 64 | 65 | if (image == null) { 66 | throw new Exception(imagePath + " cannot be decoded into a bitmap."); 67 | } 68 | 69 | Integer pageWidth = config.width; 70 | Integer width = pageWidth != null ? pageWidth : image.getWidth(); 71 | 72 | Integer pageHeight = config.height; 73 | Integer height = pageHeight != null ? pageHeight : image.getHeight(); 74 | 75 | PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo 76 | .Builder(width, height, i + 1) 77 | .create(); 78 | 79 | PdfDocument.Page page = pdfDocument.startPage(pageInfo); 80 | 81 | Bitmap scaledImage = image; 82 | 83 | if (!width.equals(image.getWidth()) || !height.equals(image.getHeight())) { 84 | ImageFit imageFit = config.imageFit; 85 | Point size = new Point(width, height); 86 | 87 | scaledImage = ImageScaling.scale(image, size, imageFit); 88 | } 89 | 90 | Canvas canvas = page.getCanvas(); 91 | if (config.backgroundColor != null) { 92 | canvas.drawColor(config.backgroundColor); 93 | } 94 | canvas.drawBitmap(scaledImage, 0, 0, null); 95 | 96 | pdfDocument.finishPage(page); 97 | } 98 | } catch (Exception e) { 99 | Log.e("ImagesPdfModule", e.getLocalizedMessage(), e); 100 | promise.reject("PDF_PAGE_CREATE_ERROR", e.getLocalizedMessage(), e); 101 | pdfDocument.close(); 102 | return; 103 | } 104 | 105 | String writtenOutputPath = null; 106 | 107 | try { 108 | writtenOutputPath = writePdfDocument(pdfDocument, outputPath); 109 | } catch (Exception e) { 110 | Log.e("ImagesPdfModule", e.getLocalizedMessage(), e); 111 | promise.reject("PDF_WRITE_ERROR", e.getLocalizedMessage(), e); 112 | pdfDocument.close(); 113 | return; 114 | } 115 | 116 | pdfDocument.close(); 117 | 118 | promise.resolve(writtenOutputPath); 119 | } catch (Exception e) { 120 | Log.e("ImagesPdfModule", e.getLocalizedMessage(), e); 121 | 122 | promise.reject("PDF_CREATE_ERROR", e.getLocalizedMessage(), e); 123 | } 124 | } 125 | 126 | @ReactMethod 127 | public void getDocumentsDirectory(Promise promise) { 128 | String docsDir = getReactApplicationContext().getExternalFilesDir(null).getAbsolutePath(); 129 | promise.resolve(docsDir); 130 | } 131 | 132 | String writePdfDocument(PdfDocument pdfDocument, String outputPath) throws IOException { 133 | OutputStream outputStream = null; 134 | Uri outputUri = null; 135 | String writtenOutputPath = null; 136 | 137 | try { 138 | outputUri = Uri.parse(outputPath); 139 | writtenOutputPath = outputUri.getPath(); 140 | 141 | String scheme = outputUri.getScheme(); 142 | 143 | if (scheme == null || scheme.equals(ContentResolver.SCHEME_FILE)) { 144 | outputStream = new FileOutputStream(writtenOutputPath); 145 | } else { 146 | throw new UnsupportedOperationException("Unsupported scheme: " + scheme); 147 | } 148 | 149 | pdfDocument.writeTo(outputStream); 150 | } finally { 151 | if (outputStream != null) { 152 | outputStream.close(); 153 | } 154 | } 155 | 156 | return writtenOutputPath; 157 | } 158 | 159 | Bitmap getBitmapFromPathOrUri(String pathOrUri) throws IOException { 160 | Bitmap bitmap = null; 161 | InputStream inputStream = null; 162 | 163 | try { 164 | byte[] base64Decoded = null; 165 | 166 | try { 167 | String base64Str = pathOrUri.replaceFirst("^data:image/[a-z]+;base64,", ""); 168 | base64Decoded = BaseEncoding.base64().decode(base64Str); 169 | } catch (IllegalArgumentException ignored) { 170 | } 171 | 172 | if (base64Decoded != null) { 173 | bitmap = BitmapFactory.decodeByteArray(base64Decoded, 0, base64Decoded.length); 174 | } else { 175 | Uri uri = Uri.parse(pathOrUri); 176 | 177 | String scheme = uri.getScheme(); 178 | 179 | if (scheme != null && scheme.equals(ContentResolver.SCHEME_CONTENT)) { 180 | ContentResolver contentResolver = getReactApplicationContext() 181 | .getContentResolver(); 182 | 183 | inputStream = contentResolver 184 | .openInputStream(uri); 185 | } else if (scheme == null || scheme.equals(ContentResolver.SCHEME_FILE)) { 186 | inputStream = new FileInputStream(uri.getPath()); 187 | } else { 188 | throw new UnsupportedOperationException("Unsupported scheme: " + uri.getScheme()); 189 | } 190 | 191 | if (inputStream != null) { 192 | bitmap = BitmapFactory 193 | .decodeStream(inputStream); 194 | } 195 | } 196 | } finally { 197 | if (inputStream != null) { 198 | inputStream.close(); 199 | } 200 | } 201 | 202 | return bitmap; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /android/src/main/java/com/imagespdf/ImagesPdfPackage.java: -------------------------------------------------------------------------------- 1 | package com.imagespdf; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class ImagesPdfPackage implements ReactPackage { 15 | @NonNull 16 | @Override 17 | public List createNativeModules(@NonNull ReactApplicationContext reactContext) { 18 | List modules = new ArrayList<>(); 19 | modules.add(new ImagesPdfModule(reactContext)); 20 | return modules; 21 | } 22 | 23 | @NonNull 24 | @Override 25 | public List createViewManagers(@NonNull ReactApplicationContext reactContext) { 26 | return Collections.emptyList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/example-android.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/docs/example-android.gif -------------------------------------------------------------------------------- /docs/example-ios.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/docs/example-ios.gif -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /example/.node-version: -------------------------------------------------------------------------------- 1 | 18 2 | -------------------------------------------------------------------------------- /example/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.6 2 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby File.read(File.join(__dir__, '.ruby-version')).strip 5 | 6 | gem 'cocoapods', '~> 1.11', '>= 1.11.3' 7 | -------------------------------------------------------------------------------- /example/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (3.0.6) 5 | rexml 6 | activesupport (7.0.4.2) 7 | concurrent-ruby (~> 1.0, >= 1.0.2) 8 | i18n (>= 1.6, < 2) 9 | minitest (>= 5.1) 10 | tzinfo (~> 2.0) 11 | addressable (2.8.1) 12 | public_suffix (>= 2.0.2, < 6.0) 13 | algoliasearch (1.27.5) 14 | httpclient (~> 2.8, >= 2.8.3) 15 | json (>= 1.5.1) 16 | atomos (0.1.3) 17 | claide (1.1.0) 18 | cocoapods (1.12.0) 19 | addressable (~> 2.8) 20 | claide (>= 1.0.2, < 2.0) 21 | cocoapods-core (= 1.12.0) 22 | cocoapods-deintegrate (>= 1.0.3, < 2.0) 23 | cocoapods-downloader (>= 1.6.0, < 2.0) 24 | cocoapods-plugins (>= 1.0.0, < 2.0) 25 | cocoapods-search (>= 1.0.0, < 2.0) 26 | cocoapods-trunk (>= 1.6.0, < 2.0) 27 | cocoapods-try (>= 1.1.0, < 2.0) 28 | colored2 (~> 3.1) 29 | escape (~> 0.0.4) 30 | fourflusher (>= 2.3.0, < 3.0) 31 | gh_inspector (~> 1.0) 32 | molinillo (~> 0.8.0) 33 | nap (~> 1.0) 34 | ruby-macho (>= 2.3.0, < 3.0) 35 | xcodeproj (>= 1.21.0, < 2.0) 36 | cocoapods-core (1.12.0) 37 | activesupport (>= 5.0, < 8) 38 | addressable (~> 2.8) 39 | algoliasearch (~> 1.0) 40 | concurrent-ruby (~> 1.1) 41 | fuzzy_match (~> 2.0.4) 42 | nap (~> 1.0) 43 | netrc (~> 0.11) 44 | public_suffix (~> 4.0) 45 | typhoeus (~> 1.0) 46 | cocoapods-deintegrate (1.0.5) 47 | cocoapods-downloader (1.6.3) 48 | cocoapods-plugins (1.0.0) 49 | nap 50 | cocoapods-search (1.0.1) 51 | cocoapods-trunk (1.6.0) 52 | nap (>= 0.8, < 2.0) 53 | netrc (~> 0.11) 54 | cocoapods-try (1.2.0) 55 | colored2 (3.1.2) 56 | concurrent-ruby (1.2.2) 57 | escape (0.0.4) 58 | ethon (0.16.0) 59 | ffi (>= 1.15.0) 60 | ffi (1.15.5) 61 | fourflusher (2.3.1) 62 | fuzzy_match (2.0.4) 63 | gh_inspector (1.1.3) 64 | httpclient (2.8.3) 65 | i18n (1.12.0) 66 | concurrent-ruby (~> 1.0) 67 | json (2.6.3) 68 | minitest (5.17.0) 69 | molinillo (0.8.0) 70 | nanaimo (0.3.0) 71 | nap (1.1.0) 72 | netrc (0.11.0) 73 | public_suffix (4.0.7) 74 | rexml (3.2.5) 75 | ruby-macho (2.5.1) 76 | typhoeus (1.4.0) 77 | ethon (>= 0.9.0) 78 | tzinfo (2.0.6) 79 | concurrent-ruby (~> 1.0) 80 | xcodeproj (1.22.0) 81 | CFPropertyList (>= 2.3.3, < 4.0) 82 | atomos (~> 0.1.3) 83 | claide (>= 1.0.2, < 2.0) 84 | colored2 (~> 3.1) 85 | nanaimo (~> 0.3.0) 86 | rexml (~> 3.2.4) 87 | 88 | PLATFORMS 89 | ruby 90 | 91 | DEPENDENCIES 92 | cocoapods (~> 1.11, >= 1.11.3) 93 | 94 | RUBY VERSION 95 | ruby 2.7.6p219 96 | 97 | BUNDLED WITH 98 | 2.4.1 99 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "com.facebook.react" 3 | 4 | import com.android.build.OutputFile 5 | 6 | /** 7 | * This is the configuration block to customize your React Native Android app. 8 | * By default you don't need to apply any configuration, just uncomment the lines you need. 9 | */ 10 | react { 11 | /* Folders */ 12 | // The root of your project, i.e. where "package.json" lives. Default is '..' 13 | // root = file("../") 14 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 15 | // reactNativeDir = file("../node_modules/react-native") 16 | // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen 17 | // codegenDir = file("../node_modules/react-native-codegen") 18 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 19 | // cliFile = file("../node_modules/react-native/cli.js") 20 | 21 | /* Variants */ 22 | // The list of variants to that are debuggable. For those we're going to 23 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 24 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 25 | // debuggableVariants = ["liteDebug", "prodDebug"] 26 | 27 | /* Bundling */ 28 | // A list containing the node command and its flags. Default is just 'node'. 29 | // nodeExecutableAndArgs = ["node"] 30 | // 31 | // The command to run when bundling. By default is 'bundle' 32 | // bundleCommand = "ram-bundle" 33 | // 34 | // The path to the CLI configuration file. Default is empty. 35 | // bundleConfig = file(../rn-cli.config.js) 36 | // 37 | // The name of the generated asset file containing your JS bundle 38 | // bundleAssetName = "MyApplication.android.bundle" 39 | // 40 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 41 | // entryFile = file("../js/MyApplication.android.js") 42 | // 43 | // A list of extra flags to pass to the 'bundle' commands. 44 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 45 | // extraPackagerArgs = [] 46 | 47 | /* Hermes Commands */ 48 | // The hermes compiler command to run. By default it is 'hermesc' 49 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 50 | // 51 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 52 | // hermesFlags = ["-O", "-output-source-map"] 53 | } 54 | 55 | /** 56 | * Set this to true to create four separate APKs instead of one, 57 | * one for each native architecture. This is useful if you don't 58 | * use App Bundles (https://developer.android.com/guide/app-bundle/) 59 | * and want to have separate APKs to upload to the Play Store. 60 | */ 61 | def enableSeparateBuildPerCPUArchitecture = false 62 | 63 | /** 64 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 65 | */ 66 | def enableProguardInReleaseBuilds = false 67 | 68 | /** 69 | * The preferred build flavor of JavaScriptCore (JSC) 70 | * 71 | * For example, to use the international variant, you can use: 72 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 73 | * 74 | * The international variant includes ICU i18n library and necessary data 75 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 76 | * give correct results when using with locales other than en-US. Note that 77 | * this variant is about 6MiB larger per architecture than default. 78 | */ 79 | def jscFlavor = 'org.webkit:android-jsc:+' 80 | 81 | /** 82 | * Private function to get the list of Native Architectures you want to build. 83 | * This reads the value from reactNativeArchitectures in your gradle.properties 84 | * file and works together with the --active-arch-only flag of react-native run-android. 85 | */ 86 | def reactNativeArchitectures() { 87 | def value = project.getProperties().get("reactNativeArchitectures") 88 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 89 | } 90 | 91 | android { 92 | ndkVersion rootProject.ext.ndkVersion 93 | 94 | compileSdkVersion rootProject.ext.compileSdkVersion 95 | 96 | namespace "com.imagespdfexample" 97 | defaultConfig { 98 | applicationId "com.imagespdfexample" 99 | minSdkVersion rootProject.ext.minSdkVersion 100 | targetSdkVersion rootProject.ext.targetSdkVersion 101 | versionCode 1 102 | versionName "1.0" 103 | } 104 | 105 | splits { 106 | abi { 107 | reset() 108 | enable enableSeparateBuildPerCPUArchitecture 109 | universalApk false // If true, also generate a universal APK 110 | include (*reactNativeArchitectures()) 111 | } 112 | } 113 | signingConfigs { 114 | debug { 115 | storeFile file('debug.keystore') 116 | storePassword 'android' 117 | keyAlias 'androiddebugkey' 118 | keyPassword 'android' 119 | } 120 | } 121 | buildTypes { 122 | debug { 123 | signingConfig signingConfigs.debug 124 | } 125 | release { 126 | // Caution! In production, you need to generate your own keystore file. 127 | // see https://reactnative.dev/docs/signed-apk-android. 128 | signingConfig signingConfigs.debug 129 | minifyEnabled enableProguardInReleaseBuilds 130 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 131 | } 132 | } 133 | 134 | // applicationVariants are e.g. debug, release 135 | applicationVariants.all { variant -> 136 | variant.outputs.each { output -> 137 | // For each separate APK per architecture, set a unique version code as described here: 138 | // https://developer.android.com/studio/build/configure-apk-splits.html 139 | // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. 140 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 141 | def abi = output.getFilter(OutputFile.ABI) 142 | if (abi != null) { // null for the universal-debug, universal-release variants 143 | output.versionCodeOverride = 144 | defaultConfig.versionCode * 1000 + versionCodes.get(abi) 145 | } 146 | 147 | } 148 | } 149 | } 150 | 151 | dependencies { 152 | // The version of react-native is set by the React Native Gradle Plugin 153 | implementation("com.facebook.react:react-android") 154 | 155 | implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0") 156 | 157 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") 158 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 159 | exclude group:'com.squareup.okhttp3', module:'okhttp' 160 | } 161 | 162 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") 163 | if (hermesEnabled.toBoolean()) { 164 | implementation("com.facebook.react:hermes-android") 165 | } else { 166 | implementation jscFlavor 167 | } 168 | } 169 | 170 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 171 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/imagespdfexample/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.imagespdfexample; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 21 | import com.facebook.react.ReactInstanceEventListener; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | /** 28 | * Class responsible of loading Flipper inside your React Native application. This is the debug 29 | * flavor of it. Here you can add your own plugins and customize the Flipper setup. 30 | */ 31 | public class ReactNativeFlipper { 32 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 33 | if (FlipperUtils.shouldEnableFlipper(context)) { 34 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 35 | 36 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 37 | client.addPlugin(new DatabasesFlipperPlugin(context)); 38 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 39 | client.addPlugin(CrashReporterPlugin.getInstance()); 40 | 41 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 42 | NetworkingModule.setCustomClientBuilder( 43 | new NetworkingModule.CustomClientBuilder() { 44 | @Override 45 | public void apply(OkHttpClient.Builder builder) { 46 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 47 | } 48 | }); 49 | client.addPlugin(networkFlipperPlugin); 50 | client.start(); 51 | 52 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 53 | // Hence we run if after all native modules have been initialized 54 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 55 | if (reactContext == null) { 56 | reactInstanceManager.addReactInstanceEventListener( 57 | new ReactInstanceEventListener() { 58 | @Override 59 | public void onReactContextInitialized(ReactContext reactContext) { 60 | reactInstanceManager.removeReactInstanceEventListener(this); 61 | reactContext.runOnNativeModulesQueueThread( 62 | new Runnable() { 63 | @Override 64 | public void run() { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | }); 68 | } 69 | }); 70 | } else { 71 | client.addPlugin(new FrescoFlipperPlugin()); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/imagespdfexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.imagespdfexample; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate; 7 | 8 | public class MainActivity extends ReactActivity { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | @Override 15 | protected String getMainComponentName() { 16 | return "ImagesPdfExample"; 17 | } 18 | 19 | /** 20 | * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link 21 | * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React 22 | * (aka React 18) with two boolean flags. 23 | */ 24 | @Override 25 | protected ReactActivityDelegate createReactActivityDelegate() { 26 | return new DefaultReactActivityDelegate( 27 | this, 28 | getMainComponentName(), 29 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 30 | DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled 31 | // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). 32 | DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/imagespdfexample/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.imagespdfexample; 2 | 3 | import android.app.Application; 4 | import com.facebook.react.PackageList; 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 9 | import com.facebook.react.defaults.DefaultReactNativeHost; 10 | import com.facebook.soloader.SoLoader; 11 | import java.util.List; 12 | 13 | public class MainApplication extends Application implements ReactApplication { 14 | 15 | private final ReactNativeHost mReactNativeHost = 16 | new DefaultReactNativeHost(this) { 17 | @Override 18 | public boolean getUseDeveloperSupport() { 19 | return BuildConfig.DEBUG; 20 | } 21 | 22 | @Override 23 | protected List getPackages() { 24 | @SuppressWarnings("UnnecessaryLocalVariable") 25 | List packages = new PackageList(this).getPackages(); 26 | // Packages that cannot be autolinked yet can be added manually here, for example: 27 | // packages.add(new MyReactNativePackage()); 28 | return packages; 29 | } 30 | 31 | @Override 32 | protected String getJSMainModuleName() { 33 | return "index"; 34 | } 35 | 36 | @Override 37 | protected boolean isNewArchEnabled() { 38 | return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 39 | } 40 | 41 | @Override 42 | protected Boolean isHermesEnabled() { 43 | return BuildConfig.IS_HERMES_ENABLED; 44 | } 45 | }; 46 | 47 | @Override 48 | public ReactNativeHost getReactNativeHost() { 49 | return mReactNativeHost; 50 | } 51 | 52 | @Override 53 | public void onCreate() { 54 | super.onCreate(); 55 | SoLoader.init(this, /* native exopackage */ false); 56 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 57 | // If you opted-in for the New Architecture, we load the native entry point for this app. 58 | DefaultNewArchitectureEntryPoint.load(); 59 | } 60 | ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ImagesPdfExample 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/release/java/com/imagespdfexample/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.imagespdfexample; 8 | 9 | import android.content.Context; 10 | import com.facebook.react.ReactInstanceManager; 11 | 12 | /** 13 | * Class responsible of loading Flipper inside your React Native application. This is the release 14 | * flavor of it so it's empty as we don't want to load Flipper. 15 | */ 16 | public class ReactNativeFlipper { 17 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 18 | // Do nothing as we don't want to initialize Flipper on Release. 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "33.0.0" 6 | minSdkVersion = 21 7 | compileSdkVersion = 33 8 | targetSdkVersion = 33 9 | 10 | // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. 11 | ndkVersion = "23.1.7779620" 12 | } 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | dependencies { 18 | classpath("com.android.tools.build:gradle:7.3.1") 19 | classpath("com.facebook.react:react-native-gradle-plugin") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.125.0 29 | 30 | # Use this property to specify which architecture you want to build. 31 | # You can also override it from the CLI using 32 | # ./gradlew -PreactNativeArchitectures=x86_64 33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 34 | 35 | # Use this property to enable support to the new architecture. 36 | # This will allow you to use TurboModules and the Fabric render in 37 | # your application. You should enable this flag either if you want 38 | # to write custom TurboModules/Fabric components OR use libraries that 39 | # are providing them. 40 | newArchEnabled=false 41 | 42 | # Use this property to enable or disable the Hermes JS engine. 43 | # If set to false, you will be using JSC instead. 44 | hermesEnabled=true 45 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canciller/react-native-images-to-pdf/838473304b10c53063221677bd585ad7b8f21d48/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'ImagesPdfExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | includeBuild('../node_modules/react-native-gradle-plugin') 5 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ImagesPdfExample", 3 | "displayName": "ImagesPdfExample" 4 | } -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | extensions: ['.tsx', '.ts', '.js', '.json'], 11 | alias: { 12 | [pak.name]: path.join(__dirname, '..', pak.source), 13 | }, 14 | }, 15 | ], 16 | ], 17 | }; 18 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/ios/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.6 2 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // ImagesPdfExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample.xcodeproj/xcshareddata/xcschemes/ImagesPdfExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"ImagesPdfExample"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | #if DEBUG 20 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 21 | #else 22 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 23 | #endif 24 | } 25 | 26 | /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. 27 | /// 28 | /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html 29 | /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). 30 | /// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`. 31 | - (BOOL)concurrentRootEnabled 32 | { 33 | return true; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ImagesPdfExample 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | LSSupportsOpeningDocumentsInPlace 28 | 29 | NSAppTransportSecurity 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSPhotoLibraryUsageDescription 41 | $(PRODUCT_NAME) uses photo library to test PDF creation. 42 | UIFileSharingEnabled 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UIViewControllerBasedStatusBarAppearance 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExampleTests/ImagesPdfExampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface ImagesPdfExampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation ImagesPdfExampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 39 | if (level >= RCTLogLevelError) { 40 | redboxError = message; 41 | } 42 | }); 43 | #endif 44 | 45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 48 | 49 | foundElement = [self findSubviewInView:vc.view 50 | matching:^BOOL(UIView *view) { 51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 52 | return YES; 53 | } 54 | return NO; 55 | }]; 56 | } 57 | 58 | #ifdef DEBUG 59 | RCTSetLogFunction(RCTDefaultLogFunction); 60 | #endif 61 | 62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /example/ios/ImagesPdfExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | require_relative '../node_modules/react-native/scripts/react_native_pods' 2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 3 | 4 | platform :ios, min_ios_version_supported 5 | prepare_react_native_project! 6 | 7 | # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. 8 | # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded 9 | # 10 | # To fix this you can also exclude `react-native-flipper` using a `react-native.config.js` 11 | # ```js 12 | # module.exports = { 13 | # dependencies: { 14 | # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), 15 | # ``` 16 | flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled 17 | 18 | linkage = ENV['USE_FRAMEWORKS'] 19 | if linkage != nil 20 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 21 | use_frameworks! :linkage => linkage.to_sym 22 | end 23 | 24 | target 'ImagesPdfExample' do 25 | config = use_native_modules! 26 | 27 | # Flags change depending on the env values. 28 | flags = get_default_flags() 29 | 30 | use_react_native!( 31 | :path => config[:reactNativePath], 32 | # Hermes is now enabled by default. Disable by setting this flag to false. 33 | # Upcoming versions of React Native may rely on get_default_flags(), but 34 | # we make it explicit here to aid in the React Native upgrade process. 35 | :hermes_enabled => flags[:hermes_enabled], 36 | :fabric_enabled => flags[:fabric_enabled], 37 | # Enables Flipper. 38 | # 39 | # Note that if you have use_frameworks! enabled, Flipper will not work and 40 | # you should disable the next line. 41 | :flipper_configuration => flipper_config, 42 | # An absolute path to your application root. 43 | :app_path => "#{Pod::Config.instance.installation_root}/.." 44 | ) 45 | 46 | target 'ImagesPdfExampleTests' do 47 | inherit! :complete 48 | # Pods for testing 49 | end 50 | 51 | post_install do |installer| 52 | react_native_post_install( 53 | installer, 54 | # Set `mac_catalyst_enabled` to `true` in order to apply patches 55 | # necessary for Mac Catalyst builds 56 | :mac_catalyst_enabled => false 57 | ) 58 | __apply_Xcode_12_5_M1_post_install_workaround(installer) 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - boost (1.76.0) 3 | - CocoaAsyncSocket (7.6.5) 4 | - DoubleConversion (1.1.6) 5 | - FBLazyVector (0.71.3) 6 | - FBReactNativeSpec (0.71.3): 7 | - RCT-Folly (= 2021.07.22.00) 8 | - RCTRequired (= 0.71.3) 9 | - RCTTypeSafety (= 0.71.3) 10 | - React-Core (= 0.71.3) 11 | - React-jsi (= 0.71.3) 12 | - ReactCommon/turbomodule/core (= 0.71.3) 13 | - Flipper (0.125.0): 14 | - Flipper-Folly (~> 2.6) 15 | - Flipper-RSocket (~> 1.4) 16 | - Flipper-Boost-iOSX (1.76.0.1.11) 17 | - Flipper-DoubleConversion (3.2.0.1) 18 | - Flipper-Fmt (7.1.7) 19 | - Flipper-Folly (2.6.10): 20 | - Flipper-Boost-iOSX 21 | - Flipper-DoubleConversion 22 | - Flipper-Fmt (= 7.1.7) 23 | - Flipper-Glog 24 | - libevent (~> 2.1.12) 25 | - OpenSSL-Universal (= 1.1.1100) 26 | - Flipper-Glog (0.5.0.5) 27 | - Flipper-PeerTalk (0.0.4) 28 | - Flipper-RSocket (1.4.3): 29 | - Flipper-Folly (~> 2.6) 30 | - FlipperKit (0.125.0): 31 | - FlipperKit/Core (= 0.125.0) 32 | - FlipperKit/Core (0.125.0): 33 | - Flipper (~> 0.125.0) 34 | - FlipperKit/CppBridge 35 | - FlipperKit/FBCxxFollyDynamicConvert 36 | - FlipperKit/FBDefines 37 | - FlipperKit/FKPortForwarding 38 | - SocketRocket (~> 0.6.0) 39 | - FlipperKit/CppBridge (0.125.0): 40 | - Flipper (~> 0.125.0) 41 | - FlipperKit/FBCxxFollyDynamicConvert (0.125.0): 42 | - Flipper-Folly (~> 2.6) 43 | - FlipperKit/FBDefines (0.125.0) 44 | - FlipperKit/FKPortForwarding (0.125.0): 45 | - CocoaAsyncSocket (~> 7.6) 46 | - Flipper-PeerTalk (~> 0.0.4) 47 | - FlipperKit/FlipperKitHighlightOverlay (0.125.0) 48 | - FlipperKit/FlipperKitLayoutHelpers (0.125.0): 49 | - FlipperKit/Core 50 | - FlipperKit/FlipperKitHighlightOverlay 51 | - FlipperKit/FlipperKitLayoutTextSearchable 52 | - FlipperKit/FlipperKitLayoutIOSDescriptors (0.125.0): 53 | - FlipperKit/Core 54 | - FlipperKit/FlipperKitHighlightOverlay 55 | - FlipperKit/FlipperKitLayoutHelpers 56 | - YogaKit (~> 1.18) 57 | - FlipperKit/FlipperKitLayoutPlugin (0.125.0): 58 | - FlipperKit/Core 59 | - FlipperKit/FlipperKitHighlightOverlay 60 | - FlipperKit/FlipperKitLayoutHelpers 61 | - FlipperKit/FlipperKitLayoutIOSDescriptors 62 | - FlipperKit/FlipperKitLayoutTextSearchable 63 | - YogaKit (~> 1.18) 64 | - FlipperKit/FlipperKitLayoutTextSearchable (0.125.0) 65 | - FlipperKit/FlipperKitNetworkPlugin (0.125.0): 66 | - FlipperKit/Core 67 | - FlipperKit/FlipperKitReactPlugin (0.125.0): 68 | - FlipperKit/Core 69 | - FlipperKit/FlipperKitUserDefaultsPlugin (0.125.0): 70 | - FlipperKit/Core 71 | - FlipperKit/SKIOSNetworkPlugin (0.125.0): 72 | - FlipperKit/Core 73 | - FlipperKit/FlipperKitNetworkPlugin 74 | - fmt (6.2.1) 75 | - glog (0.3.5) 76 | - hermes-engine (0.71.3): 77 | - hermes-engine/Pre-built (= 0.71.3) 78 | - hermes-engine/Pre-built (0.71.3) 79 | - libevent (2.1.12) 80 | - OpenSSL-Universal (1.1.1100) 81 | - RCT-Folly (2021.07.22.00): 82 | - boost 83 | - DoubleConversion 84 | - fmt (~> 6.2.1) 85 | - glog 86 | - RCT-Folly/Default (= 2021.07.22.00) 87 | - RCT-Folly/Default (2021.07.22.00): 88 | - boost 89 | - DoubleConversion 90 | - fmt (~> 6.2.1) 91 | - glog 92 | - RCT-Folly/Futures (2021.07.22.00): 93 | - boost 94 | - DoubleConversion 95 | - fmt (~> 6.2.1) 96 | - glog 97 | - libevent 98 | - RCTRequired (0.71.3) 99 | - RCTTypeSafety (0.71.3): 100 | - FBLazyVector (= 0.71.3) 101 | - RCTRequired (= 0.71.3) 102 | - React-Core (= 0.71.3) 103 | - React (0.71.3): 104 | - React-Core (= 0.71.3) 105 | - React-Core/DevSupport (= 0.71.3) 106 | - React-Core/RCTWebSocket (= 0.71.3) 107 | - React-RCTActionSheet (= 0.71.3) 108 | - React-RCTAnimation (= 0.71.3) 109 | - React-RCTBlob (= 0.71.3) 110 | - React-RCTImage (= 0.71.3) 111 | - React-RCTLinking (= 0.71.3) 112 | - React-RCTNetwork (= 0.71.3) 113 | - React-RCTSettings (= 0.71.3) 114 | - React-RCTText (= 0.71.3) 115 | - React-RCTVibration (= 0.71.3) 116 | - React-callinvoker (0.71.3) 117 | - React-Codegen (0.71.3): 118 | - FBReactNativeSpec 119 | - hermes-engine 120 | - RCT-Folly 121 | - RCTRequired 122 | - RCTTypeSafety 123 | - React-Core 124 | - React-jsi 125 | - React-jsiexecutor 126 | - ReactCommon/turbomodule/bridging 127 | - ReactCommon/turbomodule/core 128 | - React-Core (0.71.3): 129 | - glog 130 | - hermes-engine 131 | - RCT-Folly (= 2021.07.22.00) 132 | - React-Core/Default (= 0.71.3) 133 | - React-cxxreact (= 0.71.3) 134 | - React-hermes 135 | - React-jsi (= 0.71.3) 136 | - React-jsiexecutor (= 0.71.3) 137 | - React-perflogger (= 0.71.3) 138 | - Yoga 139 | - React-Core/CoreModulesHeaders (0.71.3): 140 | - glog 141 | - hermes-engine 142 | - RCT-Folly (= 2021.07.22.00) 143 | - React-Core/Default 144 | - React-cxxreact (= 0.71.3) 145 | - React-hermes 146 | - React-jsi (= 0.71.3) 147 | - React-jsiexecutor (= 0.71.3) 148 | - React-perflogger (= 0.71.3) 149 | - Yoga 150 | - React-Core/Default (0.71.3): 151 | - glog 152 | - hermes-engine 153 | - RCT-Folly (= 2021.07.22.00) 154 | - React-cxxreact (= 0.71.3) 155 | - React-hermes 156 | - React-jsi (= 0.71.3) 157 | - React-jsiexecutor (= 0.71.3) 158 | - React-perflogger (= 0.71.3) 159 | - Yoga 160 | - React-Core/DevSupport (0.71.3): 161 | - glog 162 | - hermes-engine 163 | - RCT-Folly (= 2021.07.22.00) 164 | - React-Core/Default (= 0.71.3) 165 | - React-Core/RCTWebSocket (= 0.71.3) 166 | - React-cxxreact (= 0.71.3) 167 | - React-hermes 168 | - React-jsi (= 0.71.3) 169 | - React-jsiexecutor (= 0.71.3) 170 | - React-jsinspector (= 0.71.3) 171 | - React-perflogger (= 0.71.3) 172 | - Yoga 173 | - React-Core/RCTActionSheetHeaders (0.71.3): 174 | - glog 175 | - hermes-engine 176 | - RCT-Folly (= 2021.07.22.00) 177 | - React-Core/Default 178 | - React-cxxreact (= 0.71.3) 179 | - React-hermes 180 | - React-jsi (= 0.71.3) 181 | - React-jsiexecutor (= 0.71.3) 182 | - React-perflogger (= 0.71.3) 183 | - Yoga 184 | - React-Core/RCTAnimationHeaders (0.71.3): 185 | - glog 186 | - hermes-engine 187 | - RCT-Folly (= 2021.07.22.00) 188 | - React-Core/Default 189 | - React-cxxreact (= 0.71.3) 190 | - React-hermes 191 | - React-jsi (= 0.71.3) 192 | - React-jsiexecutor (= 0.71.3) 193 | - React-perflogger (= 0.71.3) 194 | - Yoga 195 | - React-Core/RCTBlobHeaders (0.71.3): 196 | - glog 197 | - hermes-engine 198 | - RCT-Folly (= 2021.07.22.00) 199 | - React-Core/Default 200 | - React-cxxreact (= 0.71.3) 201 | - React-hermes 202 | - React-jsi (= 0.71.3) 203 | - React-jsiexecutor (= 0.71.3) 204 | - React-perflogger (= 0.71.3) 205 | - Yoga 206 | - React-Core/RCTImageHeaders (0.71.3): 207 | - glog 208 | - hermes-engine 209 | - RCT-Folly (= 2021.07.22.00) 210 | - React-Core/Default 211 | - React-cxxreact (= 0.71.3) 212 | - React-hermes 213 | - React-jsi (= 0.71.3) 214 | - React-jsiexecutor (= 0.71.3) 215 | - React-perflogger (= 0.71.3) 216 | - Yoga 217 | - React-Core/RCTLinkingHeaders (0.71.3): 218 | - glog 219 | - hermes-engine 220 | - RCT-Folly (= 2021.07.22.00) 221 | - React-Core/Default 222 | - React-cxxreact (= 0.71.3) 223 | - React-hermes 224 | - React-jsi (= 0.71.3) 225 | - React-jsiexecutor (= 0.71.3) 226 | - React-perflogger (= 0.71.3) 227 | - Yoga 228 | - React-Core/RCTNetworkHeaders (0.71.3): 229 | - glog 230 | - hermes-engine 231 | - RCT-Folly (= 2021.07.22.00) 232 | - React-Core/Default 233 | - React-cxxreact (= 0.71.3) 234 | - React-hermes 235 | - React-jsi (= 0.71.3) 236 | - React-jsiexecutor (= 0.71.3) 237 | - React-perflogger (= 0.71.3) 238 | - Yoga 239 | - React-Core/RCTSettingsHeaders (0.71.3): 240 | - glog 241 | - hermes-engine 242 | - RCT-Folly (= 2021.07.22.00) 243 | - React-Core/Default 244 | - React-cxxreact (= 0.71.3) 245 | - React-hermes 246 | - React-jsi (= 0.71.3) 247 | - React-jsiexecutor (= 0.71.3) 248 | - React-perflogger (= 0.71.3) 249 | - Yoga 250 | - React-Core/RCTTextHeaders (0.71.3): 251 | - glog 252 | - hermes-engine 253 | - RCT-Folly (= 2021.07.22.00) 254 | - React-Core/Default 255 | - React-cxxreact (= 0.71.3) 256 | - React-hermes 257 | - React-jsi (= 0.71.3) 258 | - React-jsiexecutor (= 0.71.3) 259 | - React-perflogger (= 0.71.3) 260 | - Yoga 261 | - React-Core/RCTVibrationHeaders (0.71.3): 262 | - glog 263 | - hermes-engine 264 | - RCT-Folly (= 2021.07.22.00) 265 | - React-Core/Default 266 | - React-cxxreact (= 0.71.3) 267 | - React-hermes 268 | - React-jsi (= 0.71.3) 269 | - React-jsiexecutor (= 0.71.3) 270 | - React-perflogger (= 0.71.3) 271 | - Yoga 272 | - React-Core/RCTWebSocket (0.71.3): 273 | - glog 274 | - hermes-engine 275 | - RCT-Folly (= 2021.07.22.00) 276 | - React-Core/Default (= 0.71.3) 277 | - React-cxxreact (= 0.71.3) 278 | - React-hermes 279 | - React-jsi (= 0.71.3) 280 | - React-jsiexecutor (= 0.71.3) 281 | - React-perflogger (= 0.71.3) 282 | - Yoga 283 | - React-CoreModules (0.71.3): 284 | - RCT-Folly (= 2021.07.22.00) 285 | - RCTTypeSafety (= 0.71.3) 286 | - React-Codegen (= 0.71.3) 287 | - React-Core/CoreModulesHeaders (= 0.71.3) 288 | - React-jsi (= 0.71.3) 289 | - React-RCTBlob 290 | - React-RCTImage (= 0.71.3) 291 | - ReactCommon/turbomodule/core (= 0.71.3) 292 | - React-cxxreact (0.71.3): 293 | - boost (= 1.76.0) 294 | - DoubleConversion 295 | - glog 296 | - hermes-engine 297 | - RCT-Folly (= 2021.07.22.00) 298 | - React-callinvoker (= 0.71.3) 299 | - React-jsi (= 0.71.3) 300 | - React-jsinspector (= 0.71.3) 301 | - React-logger (= 0.71.3) 302 | - React-perflogger (= 0.71.3) 303 | - React-runtimeexecutor (= 0.71.3) 304 | - React-hermes (0.71.3): 305 | - DoubleConversion 306 | - glog 307 | - hermes-engine 308 | - RCT-Folly (= 2021.07.22.00) 309 | - RCT-Folly/Futures (= 2021.07.22.00) 310 | - React-cxxreact (= 0.71.3) 311 | - React-jsi 312 | - React-jsiexecutor (= 0.71.3) 313 | - React-jsinspector (= 0.71.3) 314 | - React-perflogger (= 0.71.3) 315 | - React-jsi (0.71.3): 316 | - boost (= 1.76.0) 317 | - DoubleConversion 318 | - glog 319 | - hermes-engine 320 | - RCT-Folly (= 2021.07.22.00) 321 | - React-jsiexecutor (0.71.3): 322 | - DoubleConversion 323 | - glog 324 | - hermes-engine 325 | - RCT-Folly (= 2021.07.22.00) 326 | - React-cxxreact (= 0.71.3) 327 | - React-jsi (= 0.71.3) 328 | - React-perflogger (= 0.71.3) 329 | - React-jsinspector (0.71.3) 330 | - React-logger (0.71.3): 331 | - glog 332 | - react-native-blob-util (0.18.6): 333 | - React-Core 334 | - react-native-image-picker (5.1.0): 335 | - React-Core 336 | - react-native-images-to-pdf (0.1.0): 337 | - React-Core 338 | - react-native-pdf (6.7.1): 339 | - React-Core 340 | - React-perflogger (0.71.3) 341 | - React-RCTActionSheet (0.71.3): 342 | - React-Core/RCTActionSheetHeaders (= 0.71.3) 343 | - React-RCTAnimation (0.71.3): 344 | - RCT-Folly (= 2021.07.22.00) 345 | - RCTTypeSafety (= 0.71.3) 346 | - React-Codegen (= 0.71.3) 347 | - React-Core/RCTAnimationHeaders (= 0.71.3) 348 | - React-jsi (= 0.71.3) 349 | - ReactCommon/turbomodule/core (= 0.71.3) 350 | - React-RCTAppDelegate (0.71.3): 351 | - RCT-Folly 352 | - RCTRequired 353 | - RCTTypeSafety 354 | - React-Core 355 | - ReactCommon/turbomodule/core 356 | - React-RCTBlob (0.71.3): 357 | - hermes-engine 358 | - RCT-Folly (= 2021.07.22.00) 359 | - React-Codegen (= 0.71.3) 360 | - React-Core/RCTBlobHeaders (= 0.71.3) 361 | - React-Core/RCTWebSocket (= 0.71.3) 362 | - React-jsi (= 0.71.3) 363 | - React-RCTNetwork (= 0.71.3) 364 | - ReactCommon/turbomodule/core (= 0.71.3) 365 | - React-RCTImage (0.71.3): 366 | - RCT-Folly (= 2021.07.22.00) 367 | - RCTTypeSafety (= 0.71.3) 368 | - React-Codegen (= 0.71.3) 369 | - React-Core/RCTImageHeaders (= 0.71.3) 370 | - React-jsi (= 0.71.3) 371 | - React-RCTNetwork (= 0.71.3) 372 | - ReactCommon/turbomodule/core (= 0.71.3) 373 | - React-RCTLinking (0.71.3): 374 | - React-Codegen (= 0.71.3) 375 | - React-Core/RCTLinkingHeaders (= 0.71.3) 376 | - React-jsi (= 0.71.3) 377 | - ReactCommon/turbomodule/core (= 0.71.3) 378 | - React-RCTNetwork (0.71.3): 379 | - RCT-Folly (= 2021.07.22.00) 380 | - RCTTypeSafety (= 0.71.3) 381 | - React-Codegen (= 0.71.3) 382 | - React-Core/RCTNetworkHeaders (= 0.71.3) 383 | - React-jsi (= 0.71.3) 384 | - ReactCommon/turbomodule/core (= 0.71.3) 385 | - React-RCTSettings (0.71.3): 386 | - RCT-Folly (= 2021.07.22.00) 387 | - RCTTypeSafety (= 0.71.3) 388 | - React-Codegen (= 0.71.3) 389 | - React-Core/RCTSettingsHeaders (= 0.71.3) 390 | - React-jsi (= 0.71.3) 391 | - ReactCommon/turbomodule/core (= 0.71.3) 392 | - React-RCTText (0.71.3): 393 | - React-Core/RCTTextHeaders (= 0.71.3) 394 | - React-RCTVibration (0.71.3): 395 | - RCT-Folly (= 2021.07.22.00) 396 | - React-Codegen (= 0.71.3) 397 | - React-Core/RCTVibrationHeaders (= 0.71.3) 398 | - React-jsi (= 0.71.3) 399 | - ReactCommon/turbomodule/core (= 0.71.3) 400 | - React-runtimeexecutor (0.71.3): 401 | - React-jsi (= 0.71.3) 402 | - ReactCommon/turbomodule/bridging (0.71.3): 403 | - DoubleConversion 404 | - glog 405 | - hermes-engine 406 | - RCT-Folly (= 2021.07.22.00) 407 | - React-callinvoker (= 0.71.3) 408 | - React-Core (= 0.71.3) 409 | - React-cxxreact (= 0.71.3) 410 | - React-jsi (= 0.71.3) 411 | - React-logger (= 0.71.3) 412 | - React-perflogger (= 0.71.3) 413 | - ReactCommon/turbomodule/core (0.71.3): 414 | - DoubleConversion 415 | - glog 416 | - hermes-engine 417 | - RCT-Folly (= 2021.07.22.00) 418 | - React-callinvoker (= 0.71.3) 419 | - React-Core (= 0.71.3) 420 | - React-cxxreact (= 0.71.3) 421 | - React-jsi (= 0.71.3) 422 | - React-logger (= 0.71.3) 423 | - React-perflogger (= 0.71.3) 424 | - SocketRocket (0.6.0) 425 | - Yoga (1.14.0) 426 | - YogaKit (1.18.1): 427 | - Yoga (~> 1.14) 428 | 429 | DEPENDENCIES: 430 | - boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`) 431 | - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) 432 | - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) 433 | - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) 434 | - Flipper (= 0.125.0) 435 | - Flipper-Boost-iOSX (= 1.76.0.1.11) 436 | - Flipper-DoubleConversion (= 3.2.0.1) 437 | - Flipper-Fmt (= 7.1.7) 438 | - Flipper-Folly (= 2.6.10) 439 | - Flipper-Glog (= 0.5.0.5) 440 | - Flipper-PeerTalk (= 0.0.4) 441 | - Flipper-RSocket (= 1.4.3) 442 | - FlipperKit (= 0.125.0) 443 | - FlipperKit/Core (= 0.125.0) 444 | - FlipperKit/CppBridge (= 0.125.0) 445 | - FlipperKit/FBCxxFollyDynamicConvert (= 0.125.0) 446 | - FlipperKit/FBDefines (= 0.125.0) 447 | - FlipperKit/FKPortForwarding (= 0.125.0) 448 | - FlipperKit/FlipperKitHighlightOverlay (= 0.125.0) 449 | - FlipperKit/FlipperKitLayoutPlugin (= 0.125.0) 450 | - FlipperKit/FlipperKitLayoutTextSearchable (= 0.125.0) 451 | - FlipperKit/FlipperKitNetworkPlugin (= 0.125.0) 452 | - FlipperKit/FlipperKitReactPlugin (= 0.125.0) 453 | - FlipperKit/FlipperKitUserDefaultsPlugin (= 0.125.0) 454 | - FlipperKit/SKIOSNetworkPlugin (= 0.125.0) 455 | - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) 456 | - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) 457 | - libevent (~> 2.1.12) 458 | - OpenSSL-Universal (= 1.1.1100) 459 | - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) 460 | - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) 461 | - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) 462 | - React (from `../node_modules/react-native/`) 463 | - React-callinvoker (from `../node_modules/react-native/ReactCommon/callinvoker`) 464 | - React-Codegen (from `build/generated/ios`) 465 | - React-Core (from `../node_modules/react-native/`) 466 | - React-Core/DevSupport (from `../node_modules/react-native/`) 467 | - React-Core/RCTWebSocket (from `../node_modules/react-native/`) 468 | - React-CoreModules (from `../node_modules/react-native/React/CoreModules`) 469 | - React-cxxreact (from `../node_modules/react-native/ReactCommon/cxxreact`) 470 | - React-hermes (from `../node_modules/react-native/ReactCommon/hermes`) 471 | - React-jsi (from `../node_modules/react-native/ReactCommon/jsi`) 472 | - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) 473 | - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) 474 | - React-logger (from `../node_modules/react-native/ReactCommon/logger`) 475 | - react-native-blob-util (from `../node_modules/react-native-blob-util`) 476 | - react-native-image-picker (from `../node_modules/react-native-image-picker`) 477 | - react-native-images-to-pdf (from `../..`) 478 | - react-native-pdf (from `../node_modules/react-native-pdf`) 479 | - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) 480 | - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) 481 | - React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) 482 | - React-RCTAppDelegate (from `../node_modules/react-native/Libraries/AppDelegate`) 483 | - React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`) 484 | - React-RCTImage (from `../node_modules/react-native/Libraries/Image`) 485 | - React-RCTLinking (from `../node_modules/react-native/Libraries/LinkingIOS`) 486 | - React-RCTNetwork (from `../node_modules/react-native/Libraries/Network`) 487 | - React-RCTSettings (from `../node_modules/react-native/Libraries/Settings`) 488 | - React-RCTText (from `../node_modules/react-native/Libraries/Text`) 489 | - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) 490 | - React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`) 491 | - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) 492 | - Yoga (from `../node_modules/react-native/ReactCommon/yoga`) 493 | 494 | SPEC REPOS: 495 | trunk: 496 | - CocoaAsyncSocket 497 | - Flipper 498 | - Flipper-Boost-iOSX 499 | - Flipper-DoubleConversion 500 | - Flipper-Fmt 501 | - Flipper-Folly 502 | - Flipper-Glog 503 | - Flipper-PeerTalk 504 | - Flipper-RSocket 505 | - FlipperKit 506 | - fmt 507 | - libevent 508 | - OpenSSL-Universal 509 | - SocketRocket 510 | - YogaKit 511 | 512 | EXTERNAL SOURCES: 513 | boost: 514 | :podspec: "../node_modules/react-native/third-party-podspecs/boost.podspec" 515 | DoubleConversion: 516 | :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec" 517 | FBLazyVector: 518 | :path: "../node_modules/react-native/Libraries/FBLazyVector" 519 | FBReactNativeSpec: 520 | :path: "../node_modules/react-native/React/FBReactNativeSpec" 521 | glog: 522 | :podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec" 523 | hermes-engine: 524 | :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" 525 | RCT-Folly: 526 | :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" 527 | RCTRequired: 528 | :path: "../node_modules/react-native/Libraries/RCTRequired" 529 | RCTTypeSafety: 530 | :path: "../node_modules/react-native/Libraries/TypeSafety" 531 | React: 532 | :path: "../node_modules/react-native/" 533 | React-callinvoker: 534 | :path: "../node_modules/react-native/ReactCommon/callinvoker" 535 | React-Codegen: 536 | :path: build/generated/ios 537 | React-Core: 538 | :path: "../node_modules/react-native/" 539 | React-CoreModules: 540 | :path: "../node_modules/react-native/React/CoreModules" 541 | React-cxxreact: 542 | :path: "../node_modules/react-native/ReactCommon/cxxreact" 543 | React-hermes: 544 | :path: "../node_modules/react-native/ReactCommon/hermes" 545 | React-jsi: 546 | :path: "../node_modules/react-native/ReactCommon/jsi" 547 | React-jsiexecutor: 548 | :path: "../node_modules/react-native/ReactCommon/jsiexecutor" 549 | React-jsinspector: 550 | :path: "../node_modules/react-native/ReactCommon/jsinspector" 551 | React-logger: 552 | :path: "../node_modules/react-native/ReactCommon/logger" 553 | react-native-blob-util: 554 | :path: "../node_modules/react-native-blob-util" 555 | react-native-image-picker: 556 | :path: "../node_modules/react-native-image-picker" 557 | react-native-images-to-pdf: 558 | :path: "../.." 559 | react-native-pdf: 560 | :path: "../node_modules/react-native-pdf" 561 | React-perflogger: 562 | :path: "../node_modules/react-native/ReactCommon/reactperflogger" 563 | React-RCTActionSheet: 564 | :path: "../node_modules/react-native/Libraries/ActionSheetIOS" 565 | React-RCTAnimation: 566 | :path: "../node_modules/react-native/Libraries/NativeAnimation" 567 | React-RCTAppDelegate: 568 | :path: "../node_modules/react-native/Libraries/AppDelegate" 569 | React-RCTBlob: 570 | :path: "../node_modules/react-native/Libraries/Blob" 571 | React-RCTImage: 572 | :path: "../node_modules/react-native/Libraries/Image" 573 | React-RCTLinking: 574 | :path: "../node_modules/react-native/Libraries/LinkingIOS" 575 | React-RCTNetwork: 576 | :path: "../node_modules/react-native/Libraries/Network" 577 | React-RCTSettings: 578 | :path: "../node_modules/react-native/Libraries/Settings" 579 | React-RCTText: 580 | :path: "../node_modules/react-native/Libraries/Text" 581 | React-RCTVibration: 582 | :path: "../node_modules/react-native/Libraries/Vibration" 583 | React-runtimeexecutor: 584 | :path: "../node_modules/react-native/ReactCommon/runtimeexecutor" 585 | ReactCommon: 586 | :path: "../node_modules/react-native/ReactCommon" 587 | Yoga: 588 | :path: "../node_modules/react-native/ReactCommon/yoga" 589 | 590 | SPEC CHECKSUMS: 591 | boost: 57d2868c099736d80fcd648bf211b4431e51a558 592 | CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 593 | DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 594 | FBLazyVector: 60195509584153283780abdac5569feffb8f08cc 595 | FBReactNativeSpec: 9c191fb58d06dc05ab5559a5505fc32139e9e4a2 596 | Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0 597 | Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c 598 | Flipper-DoubleConversion: 2dc99b02f658daf147069aad9dbd29d8feb06d30 599 | Flipper-Fmt: 60cbdd92fc254826e61d669a5d87ef7015396a9b 600 | Flipper-Folly: 584845625005ff068a6ebf41f857f468decd26b3 601 | Flipper-Glog: 70c50ce58ddaf67dc35180db05f191692570f446 602 | Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9 603 | Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541 604 | FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86 605 | fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 606 | glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b 607 | hermes-engine: 38bfe887e456b33b697187570a08de33969f5db7 608 | libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 609 | OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c 610 | RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 611 | RCTRequired: bec48f07daf7bcdc2655a0cde84e07d24d2a9e2a 612 | RCTTypeSafety: 171394eebacf71e1cfad79dbfae7ee8fc16ca80a 613 | React: d7433ccb6a8c36e4cbed59a73c0700fc83c3e98a 614 | React-callinvoker: 15f165009bd22ae829b2b600e50bcc98076ce4b8 615 | React-Codegen: b5910000eaf1e0c2f47d29be6f82f5f1264420d7 616 | React-Core: b6f2f78d580a90b83fd7b0d1c6911c799f6eac82 617 | React-CoreModules: e0cbc1a4f4f3f60e23c476fef7ab37be363ea8c1 618 | React-cxxreact: c87f3f124b2117d00d410b35f16c2257e25e50fa 619 | React-hermes: c64ca6bdf16a7069773103c9bedaf30ec90ab38f 620 | React-jsi: 39729361645568e238081b3b3180fbad803f25a4 621 | React-jsiexecutor: 515b703d23ffadeac7687bc2d12fb08b90f0aaa1 622 | React-jsinspector: 9f7c9137605e72ca0343db4cea88006cb94856dd 623 | React-logger: 957e5dc96d9dbffc6e0f15e0ee4d2b42829ff207 624 | react-native-blob-util: c5430d091e011b7fc57f888c356da2a2ff8dc8ad 625 | react-native-image-picker: c33d4e79f0a14a2b66e5065e14946ae63749660b 626 | react-native-images-to-pdf: 52c7735ec408cf3d8e81be026b36c62c7a18aaa3 627 | react-native-pdf: 7c0e91ada997bac8bac3bb5bea5b6b81f5a3caae 628 | React-perflogger: af8a3d31546077f42d729b949925cc4549f14def 629 | React-RCTActionSheet: 57cc5adfefbaaf0aae2cf7e10bccd746f2903673 630 | React-RCTAnimation: 11c61e94da700c4dc915cf134513764d87fc5e2b 631 | React-RCTAppDelegate: c3980adeaadcfd6cb495532e928b36ac6db3c14a 632 | React-RCTBlob: ccc5049d742b41971141415ca86b83b201495695 633 | React-RCTImage: 7a9226b0944f1e76e8e01e35a9245c2477cdbabb 634 | React-RCTLinking: bbe8cc582046a9c04f79c235b73c93700263e8b4 635 | React-RCTNetwork: fc2ca322159dc54e06508d4f5c3e934da63dc013 636 | React-RCTSettings: f1e9db2cdf946426d3f2b210e4ff4ce0f0d842ef 637 | React-RCTText: 1c41dd57e5d742b1396b4eeb251851ce7ff0fca1 638 | React-RCTVibration: 5199a180d04873366a83855de55ac33ce60fe4d5 639 | React-runtimeexecutor: 7bf0dafc7b727d93c8cb94eb00a9d3753c446c3e 640 | ReactCommon: 6f65ea5b7d84deb9e386f670dd11ce499ded7b40 641 | SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 642 | Yoga: 5ed1699acbba8863755998a4245daa200ff3817b 643 | YogaKit: f782866e155069a2cca2517aafea43200b01fd5a 644 | 645 | PODFILE CHECKSUM: e4d2b9da1562c096775c6f958bcad1abed773607 646 | 647 | COCOAPODS: 1.12.0 648 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const escape = require('escape-string-regexp'); 3 | const exclusionList = require('metro-config/src/defaults/exclusionList'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we block them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: exclusionList( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ImagesPdfExample", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "pods": "pod-install --quiet" 10 | }, 11 | "dependencies": { 12 | "react": "18.2.0", 13 | "react-native": "0.71.3", 14 | "react-native-blob-util": "^0.18.6", 15 | "react-native-image-picker": "^5.1.0", 16 | "react-native-pdf": "^6.7.1" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "^7.20.0", 20 | "@babel/preset-env": "^7.20.0", 21 | "@babel/runtime": "^7.20.0", 22 | "babel-plugin-module-resolver": "^4.1.0", 23 | "metro-react-native-babel-preset": "0.73.7" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | dependencies: { 6 | [pak.name]: { 7 | root: path.join(__dirname, '..'), 8 | }, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { createPdf, ImageFit, Page } from 'react-native-images-to-pdf'; 4 | import { launchImageLibrary } from 'react-native-image-picker'; 5 | import RNBlobUtil from 'react-native-blob-util'; 6 | import Pdf from 'react-native-pdf'; 7 | import { 8 | StyleSheet, 9 | Text, 10 | TextInput, 11 | TouchableOpacity, 12 | View, 13 | } from 'react-native'; 14 | 15 | export default function App() { 16 | const [uri, setUri] = React.useState(''); 17 | const [isLoading, setIsLoading] = React.useState(false); 18 | const [width, setWidth] = React.useState(594); 19 | const [height, setHeight] = React.useState(842); 20 | const [backgroundColor, setBackgroundColor] = React.useState('black'); 21 | const [imageFit, setImageFit] = React.useState( 22 | 'contain' 23 | ); 24 | 25 | const parts: string[] = []; 26 | if (width) { 27 | parts.push(`${width}w`); 28 | } 29 | if (height) { 30 | parts.push(`${height}h`); 31 | } 32 | parts.push(imageFit ?? 'none'); 33 | 34 | const outputFilename = parts.join('-') + '.pdf'; 35 | 36 | const selectImages = async () => { 37 | setIsLoading(true); 38 | 39 | try { 40 | const result = await launchImageLibrary({ 41 | mediaType: 'photo', 42 | selectionLimit: 0, 43 | }); 44 | 45 | if (result.assets) { 46 | const pages: Page[] = []; 47 | 48 | for (let asset of result.assets) { 49 | const uri = asset.uri as string; 50 | 51 | // const mimeType = asset.type as string; 52 | // 53 | // const base64 = await RNBlobUtil.fs.readFile( 54 | // uri.replace('file://', ''), 55 | // 'base64' 56 | // ); 57 | // 58 | // const imagePath = `data:${mimeType};base64,${base64}`; 59 | 60 | pages.push({ 61 | imagePath: uri, 62 | imageFit, 63 | width, 64 | height, 65 | backgroundColor, 66 | }); 67 | } 68 | 69 | const uri = await createPdf({ 70 | outputPath: `file://${RNBlobUtil.fs.dirs.DocumentDir}/${outputFilename}`, 71 | pages, 72 | }); 73 | 74 | console.log('PDF created successfully:', uri); 75 | 76 | setUri(uri); 77 | } 78 | } catch (e) { 79 | console.error('Failed to create PDF:', e); 80 | } 81 | 82 | setIsLoading(false); 83 | }; 84 | 85 | if (uri) { 86 | return ( 87 | 88 | 95 | setUri('')} 104 | > 105 | Close 106 | 107 | 108 | ); 109 | } 110 | 111 | return ( 112 | 113 | { 119 | const n = parseFloat(text); 120 | setWidth(Number.isNaN(n) ? undefined : n); 121 | }} 122 | /> 123 | { 129 | const n = parseFloat(text); 130 | setHeight(Number.isNaN(n) ? undefined : n); 131 | }} 132 | /> 133 | 140 | { 146 | const f = text.toLowerCase(); 147 | switch (f) { 148 | case 'none': 149 | case 'cover': 150 | case 'contain': 151 | case 'fill': 152 | setImageFit(f); 153 | break; 154 | default: 155 | setImageFit(undefined); 156 | } 157 | }} 158 | /> 159 | 160 | 170 | 171 | {isLoading ? 'Loading...' : 'Press to select images'} 172 | 173 | 174 | 175 | 176 | Page width: {width ?? 'image width'} 177 | 178 | 179 | Page height: {height ?? 'image height'} 180 | 181 | 182 | Image fit: {imageFit ?? 'none'} 183 | 184 | 185 | Output file name: {outputFilename} 186 | 187 | 188 | ); 189 | } 190 | 191 | const styles = StyleSheet.create({ 192 | root: { 193 | flex: 1, 194 | justifyContent: 'center', 195 | padding: 20, 196 | }, 197 | input: { 198 | marginBottom: 20, 199 | borderWidth: 1, 200 | borderColor: '#32a9d9', 201 | borderRadius: 10, 202 | paddingHorizontal: 10, 203 | minHeight: 40, 204 | }, 205 | button: { 206 | backgroundColor: '#32a9d9', 207 | padding: 10, 208 | borderRadius: 10, 209 | }, 210 | buttonText: { 211 | color: 'white', 212 | fontWeight: 'bold', 213 | textTransform: 'uppercase', 214 | textAlign: 'center', 215 | }, 216 | bold: { 217 | fontWeight: 'bold', 218 | }, 219 | }); 220 | -------------------------------------------------------------------------------- /ios/CreatePdfError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CreatePdfError.swift 3 | // ImagesPdf 4 | // 5 | // Created by Gabriel Emilio Lopez Ojeda on 06/03/23. 6 | // Copyright © 2023 Facebook. All rights reserved. 7 | // 8 | 9 | enum CreatePdfError: Error { 10 | case pdfPageCreateError(error: Error) 11 | case pdfWriteError(error: Error) 12 | case outputDirectoryDoesNotExist 13 | case outputDirectoryIsNotWritable 14 | case noImagesProvided 15 | } 16 | -------------------------------------------------------------------------------- /ios/CreatePdfOptions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CreatePdfOptions.swift 3 | // ImagesPdf 4 | // 5 | // Created by Gabriel Emilio Lopez Ojeda on 06/03/23. 6 | // Copyright © 2023 Facebook. All rights reserved. 7 | // 8 | 9 | enum ImageFit: String, Decodable { 10 | case none 11 | case fill 12 | case contain 13 | case cover 14 | } 15 | 16 | struct Page: Decodable { 17 | let imagePath: String 18 | let imageFit: ImageFit? 19 | let width: Double? 20 | let height: Double? 21 | let backgroundColor: Int? 22 | } 23 | 24 | class CreatePdfOptions: Decodable { 25 | let outputPath: String 26 | let pages: [Page] 27 | 28 | init(_ options: NSDictionary) throws { 29 | let jsonData = try JSONSerialization.data(withJSONObject: options, options: []) 30 | let pdfCreateOptions = try JSONDecoder().decode(CreatePdfOptions.self, from: jsonData) 31 | 32 | self.outputPath = pdfCreateOptions.outputPath 33 | self.pages = pdfCreateOptions.pages 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ios/ImagesPdf-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | -------------------------------------------------------------------------------- /ios/ImagesPdf.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface RCT_EXTERN_MODULE(ImagesPdf, NSObject) 4 | 5 | RCT_EXTERN_METHOD( 6 | createPdf: (NSDictionary)options 7 | resolver: (RCTPromiseResolveBlock)resolve 8 | rejecter: (RCTPromiseRejectBlock)reject 9 | ) 10 | 11 | RCT_EXTERN_METHOD( 12 | getDocumentsDirectory: (RCTPromiseResolveBlock)resolve 13 | rejecter: (RCTPromiseRejectBlock)reject 14 | ) 15 | 16 | + (BOOL)requiresMainQueueSetup 17 | { 18 | return NO; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /ios/ImagesPdf.swift: -------------------------------------------------------------------------------- 1 | @objc(ImagesPdf) 2 | class ImagesPdf: NSObject { 3 | let E_PDF_CREATE_ERROR = "PDF_CREATE_ERROR" 4 | let E_PDF_WRITE_ERROR = "PDF_WRITE_ERROR" 5 | let E_PDF_PAGE_CREATE_ERROR = "PDF_PAGE_CREATE_ERROR" 6 | let E_OUTPUT_DIRECTORY_DOES_NOT_EXIST = "OUTPUT_DIRECTORY_DOES_NOT_EXIST" 7 | let E_OUTPUT_DIRECTORY_IS_NOT_WRITABLE = "OUTPUT_DIRECTORY_IS_NOT_WRITABLE" 8 | let E_NO_IMAGES_PROVIDED = "NO_IMAGES_PROVIDED" 9 | 10 | @objc 11 | func createPdf(_ options: NSDictionary, resolver resolve:RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) { 12 | do { 13 | let createPdfOptions = try CreatePdfOptions(options) 14 | 15 | let outputPath = createPdfOptions.outputPath 16 | let pages = createPdfOptions.pages 17 | 18 | if pages.isEmpty { 19 | throw CreatePdfError.noImagesProvided 20 | } 21 | 22 | let data = try renderPdfData(pages) 23 | 24 | let writtenOutputPath = try writePdfFile(data: data, 25 | outputPath: outputPath) 26 | 27 | resolve(writtenOutputPath) 28 | } catch CreatePdfError.noImagesProvided { 29 | reject(E_NO_IMAGES_PROVIDED, 30 | "No images provided.", 31 | nil) 32 | } catch CreatePdfError.outputDirectoryIsNotWritable { 33 | reject(E_OUTPUT_DIRECTORY_IS_NOT_WRITABLE, 34 | "outputDirectory is not writable.", 35 | nil) 36 | } catch CreatePdfError.outputDirectoryDoesNotExist { 37 | reject(E_OUTPUT_DIRECTORY_DOES_NOT_EXIST, 38 | "outputDirectory does not exist.", 39 | nil) 40 | } catch CreatePdfError.pdfPageCreateError(let error) { 41 | reject(E_PDF_PAGE_CREATE_ERROR, 42 | error.localizedDescription, 43 | error) 44 | } catch CreatePdfError.pdfWriteError(let error) { 45 | reject(E_PDF_WRITE_ERROR, 46 | error.localizedDescription, 47 | error) 48 | } catch { 49 | reject(E_PDF_CREATE_ERROR, 50 | error.localizedDescription, 51 | error) 52 | } 53 | } 54 | 55 | func renderPdfData(_ pages: [Page]) throws -> Data { 56 | let renderer = UIGraphicsPDFRenderer() 57 | var pageError: Error? = nil 58 | 59 | let data = renderer.pdfData {(context) in 60 | for page in pages { 61 | let imageUrl = URL(string: page.imagePath)! 62 | var image: UIImage? = nil 63 | 64 | do { 65 | let imageData = try Data(contentsOf: imageUrl) 66 | image = UIImage(data: imageData) 67 | } catch { 68 | pageError = error 69 | break 70 | } 71 | 72 | if let image = image { 73 | let width = page.width ?? image.size.width 74 | let height = page.height ?? image.size.height 75 | 76 | let pageBounds = CGRect(x: 0, y: 0, width: width, height: height) 77 | context.beginPage(withBounds: pageBounds, pageInfo: [:]) 78 | 79 | 80 | if let backgroudColorInt = page.backgroundColor { 81 | let backgroundColor = createUIColor(from: backgroudColorInt).cgColor 82 | context.cgContext.setFillColor(backgroundColor) 83 | context.cgContext.fill(pageBounds) 84 | } 85 | 86 | var scaledImage: UIImage? 87 | if width != image.size.width || height != image.size.height { 88 | let fit = page.imageFit 89 | let size = CGSize(width: width, height: height) 90 | 91 | scaledImage = image.scale(to: size, with: fit) 92 | } else { 93 | scaledImage = image 94 | } 95 | 96 | scaledImage?.draw(at: .zero) 97 | } 98 | } 99 | } 100 | 101 | if let pageError = pageError { 102 | throw CreatePdfError.pdfPageCreateError(error: pageError) 103 | } 104 | 105 | return data 106 | } 107 | 108 | func writePdfFile(data: Data, outputPath: String) throws -> String { 109 | let url = URL(string: outputPath)! 110 | 111 | do { 112 | try data.write(to: url) 113 | } catch { 114 | throw CreatePdfError.pdfWriteError(error: error) 115 | } 116 | 117 | return url.absoluteString 118 | } 119 | 120 | @objc 121 | func getDocumentsDirectory(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) { 122 | let docsDirUrl = getDocumentsDirectoryURL() 123 | 124 | var docsDir = docsDirUrl.absoluteString 125 | docsDir.removeLast() 126 | 127 | resolve(docsDir) 128 | } 129 | 130 | func getDocumentsDirectoryURL() -> URL { 131 | let docsDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) 132 | return docsDir 133 | } 134 | 135 | func createUIColor(from color: Int) -> UIColor { 136 | let red = CGFloat((color >> 16) & 0xFF) / 255.0 137 | let green = CGFloat((color >> 8) & 0xFF) / 255.0 138 | let blue = CGFloat(color & 0xFF) / 255.0 139 | let alpha = CGFloat((color >> 24) & 0xFF) / 255.0 140 | 141 | return UIColor(red: red, green: green, blue: blue, alpha: alpha) 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /ios/ImagesPdf.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 527793C229B68D9100DA97C8 /* CreatePdfOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527793C129B68D8700DA97C8 /* CreatePdfOptions.swift */; }; 11 | 527793C629B6E17300DA97C8 /* CreatePdfError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527793C529B6E17300DA97C8 /* CreatePdfError.swift */; }; 12 | 528FC83B2A3A80D400B91589 /* UIImage+Scaling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 528FC83A2A3A80D400B91589 /* UIImage+Scaling.swift */; }; 13 | F4FF95D7245B92E800C19C63 /* ImagesPdf.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* ImagesPdf.swift */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXCopyFilesBuildPhase section */ 17 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 18 | isa = PBXCopyFilesBuildPhase; 19 | buildActionMask = 2147483647; 20 | dstPath = "include/$(PRODUCT_NAME)"; 21 | dstSubfolderSpec = 16; 22 | files = ( 23 | ); 24 | runOnlyForDeploymentPostprocessing = 0; 25 | }; 26 | /* End PBXCopyFilesBuildPhase section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 134814201AA4EA6300B7C361 /* libImagesPdf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libImagesPdf.a; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 527793C129B68D8700DA97C8 /* CreatePdfOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePdfOptions.swift; sourceTree = ""; }; 31 | 527793C529B6E17300DA97C8 /* CreatePdfError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePdfError.swift; sourceTree = ""; }; 32 | 528FC83A2A3A80D400B91589 /* UIImage+Scaling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Scaling.swift"; sourceTree = ""; }; 33 | B3E7B5891CC2AC0600A0062D /* ImagesPdf.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImagesPdf.m; sourceTree = ""; }; 34 | F4FF95D5245B92E700C19C63 /* ImagesPdf-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ImagesPdf-Bridging-Header.h"; sourceTree = ""; }; 35 | F4FF95D6245B92E800C19C63 /* ImagesPdf.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagesPdf.swift; sourceTree = ""; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | ); 44 | runOnlyForDeploymentPostprocessing = 0; 45 | }; 46 | /* End PBXFrameworksBuildPhase section */ 47 | 48 | /* Begin PBXGroup section */ 49 | 134814211AA4EA7D00B7C361 /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | 134814201AA4EA6300B7C361 /* libImagesPdf.a */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | 58B511D21A9E6C8500147676 = { 58 | isa = PBXGroup; 59 | children = ( 60 | 528FC83A2A3A80D400B91589 /* UIImage+Scaling.swift */, 61 | 527793C529B6E17300DA97C8 /* CreatePdfError.swift */, 62 | 527793C129B68D8700DA97C8 /* CreatePdfOptions.swift */, 63 | F4FF95D6245B92E800C19C63 /* ImagesPdf.swift */, 64 | B3E7B5891CC2AC0600A0062D /* ImagesPdf.m */, 65 | F4FF95D5245B92E700C19C63 /* ImagesPdf-Bridging-Header.h */, 66 | 134814211AA4EA7D00B7C361 /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 58B511DA1A9E6C8500147676 /* ImagesPdf */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "ImagesPdf" */; 76 | buildPhases = ( 77 | 58B511D71A9E6C8500147676 /* Sources */, 78 | 58B511D81A9E6C8500147676 /* Frameworks */, 79 | 58B511D91A9E6C8500147676 /* CopyFiles */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = ImagesPdf; 86 | productName = RCTDataManager; 87 | productReference = 134814201AA4EA6300B7C361 /* libImagesPdf.a */; 88 | productType = "com.apple.product-type.library.static"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 58B511D31A9E6C8500147676 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastUpgradeCheck = 0920; 97 | ORGANIZATIONNAME = Facebook; 98 | TargetAttributes = { 99 | 58B511DA1A9E6C8500147676 = { 100 | CreatedOnToolsVersion = 6.1.1; 101 | }; 102 | }; 103 | }; 104 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "ImagesPdf" */; 105 | compatibilityVersion = "Xcode 3.2"; 106 | developmentRegion = English; 107 | hasScannedForEncodings = 0; 108 | knownRegions = ( 109 | English, 110 | en, 111 | ); 112 | mainGroup = 58B511D21A9E6C8500147676; 113 | productRefGroup = 58B511D21A9E6C8500147676; 114 | projectDirPath = ""; 115 | projectRoot = ""; 116 | targets = ( 117 | 58B511DA1A9E6C8500147676 /* ImagesPdf */, 118 | ); 119 | }; 120 | /* End PBXProject section */ 121 | 122 | /* Begin PBXSourcesBuildPhase section */ 123 | 58B511D71A9E6C8500147676 /* Sources */ = { 124 | isa = PBXSourcesBuildPhase; 125 | buildActionMask = 2147483647; 126 | files = ( 127 | F4FF95D7245B92E800C19C63 /* ImagesPdf.swift in Sources */, 128 | 528FC83B2A3A80D400B91589 /* UIImage+Scaling.swift in Sources */, 129 | 527793C629B6E17300DA97C8 /* CreatePdfError.swift in Sources */, 130 | 527793C229B68D9100DA97C8 /* CreatePdfOptions.swift in Sources */, 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | /* End PBXSourcesBuildPhase section */ 135 | 136 | /* Begin XCBuildConfiguration section */ 137 | 58B511ED1A9E6C8500147676 /* Debug */ = { 138 | isa = XCBuildConfiguration; 139 | buildSettings = { 140 | ALWAYS_SEARCH_USER_PATHS = NO; 141 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 142 | CLANG_CXX_LIBRARY = "libc++"; 143 | CLANG_ENABLE_MODULES = YES; 144 | CLANG_ENABLE_OBJC_ARC = YES; 145 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 146 | CLANG_WARN_BOOL_CONVERSION = YES; 147 | CLANG_WARN_COMMA = YES; 148 | CLANG_WARN_CONSTANT_CONVERSION = YES; 149 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 150 | CLANG_WARN_EMPTY_BODY = YES; 151 | CLANG_WARN_ENUM_CONVERSION = YES; 152 | CLANG_WARN_INFINITE_RECURSION = YES; 153 | CLANG_WARN_INT_CONVERSION = YES; 154 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 155 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 156 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 157 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 158 | CLANG_WARN_STRICT_PROTOTYPES = YES; 159 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 160 | CLANG_WARN_UNREACHABLE_CODE = YES; 161 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 162 | COPY_PHASE_STRIP = NO; 163 | ENABLE_STRICT_OBJC_MSGSEND = YES; 164 | ENABLE_TESTABILITY = YES; 165 | "EXCLUDED_ARCHS[sdk=*]" = arm64; 166 | GCC_C_LANGUAGE_STANDARD = gnu99; 167 | GCC_DYNAMIC_NO_PIC = NO; 168 | GCC_NO_COMMON_BLOCKS = YES; 169 | GCC_OPTIMIZATION_LEVEL = 0; 170 | GCC_PREPROCESSOR_DEFINITIONS = ( 171 | "DEBUG=1", 172 | "$(inherited)", 173 | ); 174 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 175 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 176 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 177 | GCC_WARN_UNDECLARED_SELECTOR = YES; 178 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 179 | GCC_WARN_UNUSED_FUNCTION = YES; 180 | GCC_WARN_UNUSED_VARIABLE = YES; 181 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 182 | MTL_ENABLE_DEBUG_INFO = YES; 183 | ONLY_ACTIVE_ARCH = YES; 184 | SDKROOT = iphoneos; 185 | }; 186 | name = Debug; 187 | }; 188 | 58B511EE1A9E6C8500147676 /* Release */ = { 189 | isa = XCBuildConfiguration; 190 | buildSettings = { 191 | ALWAYS_SEARCH_USER_PATHS = NO; 192 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 193 | CLANG_CXX_LIBRARY = "libc++"; 194 | CLANG_ENABLE_MODULES = YES; 195 | CLANG_ENABLE_OBJC_ARC = YES; 196 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_COMMA = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 201 | CLANG_WARN_EMPTY_BODY = YES; 202 | CLANG_WARN_ENUM_CONVERSION = YES; 203 | CLANG_WARN_INFINITE_RECURSION = YES; 204 | CLANG_WARN_INT_CONVERSION = YES; 205 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 206 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 207 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 208 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 209 | CLANG_WARN_STRICT_PROTOTYPES = YES; 210 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 211 | CLANG_WARN_UNREACHABLE_CODE = YES; 212 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 213 | COPY_PHASE_STRIP = YES; 214 | ENABLE_NS_ASSERTIONS = NO; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | "EXCLUDED_ARCHS[sdk=*]" = arm64; 217 | GCC_C_LANGUAGE_STANDARD = gnu99; 218 | GCC_NO_COMMON_BLOCKS = YES; 219 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 220 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 221 | GCC_WARN_UNDECLARED_SELECTOR = YES; 222 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 223 | GCC_WARN_UNUSED_FUNCTION = YES; 224 | GCC_WARN_UNUSED_VARIABLE = YES; 225 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 226 | MTL_ENABLE_DEBUG_INFO = NO; 227 | SDKROOT = iphoneos; 228 | VALIDATE_PRODUCT = YES; 229 | }; 230 | name = Release; 231 | }; 232 | 58B511F01A9E6C8500147676 /* Debug */ = { 233 | isa = XCBuildConfiguration; 234 | buildSettings = { 235 | HEADER_SEARCH_PATHS = ( 236 | "$(inherited)", 237 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 238 | "$(SRCROOT)/../../../React/**", 239 | "$(SRCROOT)/../../react-native/React/**", 240 | ); 241 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 242 | OTHER_LDFLAGS = "-ObjC"; 243 | PRODUCT_NAME = ImagesPdf; 244 | SKIP_INSTALL = YES; 245 | SWIFT_OBJC_BRIDGING_HEADER = "ImagesPdf-Bridging-Header.h"; 246 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 247 | SWIFT_VERSION = 5.0; 248 | }; 249 | name = Debug; 250 | }; 251 | 58B511F11A9E6C8500147676 /* Release */ = { 252 | isa = XCBuildConfiguration; 253 | buildSettings = { 254 | HEADER_SEARCH_PATHS = ( 255 | "$(inherited)", 256 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 257 | "$(SRCROOT)/../../../React/**", 258 | "$(SRCROOT)/../../react-native/React/**", 259 | ); 260 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 261 | OTHER_LDFLAGS = "-ObjC"; 262 | PRODUCT_NAME = ImagesPdf; 263 | SKIP_INSTALL = YES; 264 | SWIFT_OBJC_BRIDGING_HEADER = "ImagesPdf-Bridging-Header.h"; 265 | SWIFT_VERSION = 5.0; 266 | }; 267 | name = Release; 268 | }; 269 | /* End XCBuildConfiguration section */ 270 | 271 | /* Begin XCConfigurationList section */ 272 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "ImagesPdf" */ = { 273 | isa = XCConfigurationList; 274 | buildConfigurations = ( 275 | 58B511ED1A9E6C8500147676 /* Debug */, 276 | 58B511EE1A9E6C8500147676 /* Release */, 277 | ); 278 | defaultConfigurationIsVisible = 0; 279 | defaultConfigurationName = Release; 280 | }; 281 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "ImagesPdf" */ = { 282 | isa = XCConfigurationList; 283 | buildConfigurations = ( 284 | 58B511F01A9E6C8500147676 /* Debug */, 285 | 58B511F11A9E6C8500147676 /* Release */, 286 | ); 287 | defaultConfigurationIsVisible = 0; 288 | defaultConfigurationName = Release; 289 | }; 290 | /* End XCConfigurationList section */ 291 | }; 292 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 293 | } 294 | -------------------------------------------------------------------------------- /ios/UIImage+Scaling.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Scaling.swift 3 | // ImagesPdf 4 | // 5 | // Created by Gabriel Emilio Lopez Ojeda on 14/06/23. 6 | // Copyright © 2023 Facebook. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // TODO: ImagePosition 12 | 13 | extension UIImage { 14 | func scale(to size: CGSize, with fit: ImageFit?) -> UIImage? { 15 | let fit = fit ?? .none 16 | 17 | switch fit { 18 | case .none: 19 | return scaleWithNone(to: size) 20 | case .contain: 21 | return scaleWithContain(to: size) 22 | case .cover: 23 | return scaleWithCover(to: size) 24 | case .fill: 25 | return scaleWithFill(to: size) 26 | } 27 | } 28 | 29 | private func scaleWithNone(to size: CGSize) -> UIImage? { 30 | let scaledWidth = self.size.width 31 | 32 | let origin = CGPoint( 33 | x: (size.width - self.size.width) / 2.0, 34 | y: (size.height - self.size.height) / 2.0 35 | ) 36 | 37 | UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 38 | defer { UIGraphicsEndImageContext() } 39 | 40 | self.draw(in: CGRect(origin: origin, size: self.size)) 41 | 42 | return UIGraphicsGetImageFromCurrentImageContext() 43 | } 44 | 45 | private func scaleWithContain(to size: CGSize) -> UIImage? { 46 | let aspectRatio = self.size.width / self.size.height 47 | let targetAspectRatio = size.width / size.height 48 | 49 | var scaledSize = CGSize(width: size.width, height: size.height) 50 | if aspectRatio > targetAspectRatio { 51 | scaledSize.height = size.width / aspectRatio 52 | } else { 53 | scaledSize.width = size.height * aspectRatio 54 | } 55 | 56 | let origin = CGPoint( 57 | x: (size.width - scaledSize.width) / 2.0, 58 | y: (size.height - scaledSize.height) / 2.0 59 | ) 60 | 61 | UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 62 | defer { UIGraphicsEndImageContext() } 63 | 64 | self.draw(in: CGRect(origin: origin, size: scaledSize)) 65 | 66 | return UIGraphicsGetImageFromCurrentImageContext() 67 | } 68 | 69 | private func scaleWithCover(to size: CGSize) -> UIImage? { 70 | let aspectRatio = self.size.width / self.size.height 71 | let targetAspectRatio = size.width / size.height 72 | 73 | var scaleFactor = size.width / self.size.width 74 | if aspectRatio > targetAspectRatio { 75 | scaleFactor = size.height / self.size.height 76 | } 77 | 78 | let scaledSize = CGSize( 79 | width: self.size.width * scaleFactor, 80 | height: self.size.height * scaleFactor 81 | ) 82 | 83 | let origin = CGPoint( 84 | x: (size.width - scaledSize.width) / 2.0, 85 | y: (size.height - scaledSize.height) / 2.0 86 | ) 87 | 88 | UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 89 | defer { UIGraphicsEndImageContext() } 90 | 91 | self.draw(in: CGRect(origin: origin, size: scaledSize)) 92 | 93 | return UIGraphicsGetImageFromCurrentImageContext() 94 | } 95 | 96 | private func scaleWithFill(to size: CGSize) -> UIImage? { 97 | UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 98 | defer { UIGraphicsEndImageContext() } 99 | 100 | self.draw(in: CGRect(origin: .zero, size: size)) 101 | 102 | return UIGraphicsGetImageFromCurrentImageContext() 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /lefthook.yml: -------------------------------------------------------------------------------- 1 | pre-commit: 2 | parallel: true 3 | commands: 4 | lint: 5 | files: git diff --name-only @{push} 6 | glob: '*.{js,ts,jsx,tsx}' 7 | run: npx eslint . --ext .js,.ts,.jsx,.tsx 8 | types: 9 | files: git diff --name-only @{push} 10 | glob: '*.{js,ts, jsx, tsx}' 11 | run: npx tsc --noEmit 12 | commit-msg: 13 | parallel: true 14 | commands: 15 | commitlint: 16 | run: npx commitlint --edit 17 | -------------------------------------------------------------------------------- /lib/commonjs/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.createPdf = createPdf; 7 | exports.getDocumentsDirectory = getDocumentsDirectory; 8 | var _reactNative = require("react-native"); 9 | const LINKING_ERROR = `The package 'react-native-images-to-pdf' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({ 10 | ios: "- You have run 'pod install'\n", 11 | default: '' 12 | }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; 13 | const ImagesPdf = _reactNative.NativeModules.ImagesPdf ? _reactNative.NativeModules.ImagesPdf : new Proxy({}, { 14 | get() { 15 | throw new Error(LINKING_ERROR); 16 | } 17 | }); 18 | function createPdf(options) { 19 | const { 20 | pages, 21 | ...opts 22 | } = options; 23 | const internalPages = pages.map(e => { 24 | const { 25 | backgroundColor, 26 | ...page 27 | } = e; 28 | return { 29 | backgroundColor: (0, _reactNative.processColor)(backgroundColor) ?? undefined, 30 | ...page 31 | }; 32 | }); 33 | return ImagesPdf.createPdf({ 34 | ...opts, 35 | pages: internalPages 36 | }); 37 | } 38 | function getDocumentsDirectory() { 39 | return ImagesPdf.getDocumentsDirectory(); 40 | } 41 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /lib/commonjs/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","ImagesPdf","NativeModules","Proxy","get","Error","createPdf","options","pages","opts","internalPages","map","e","backgroundColor","page","processColor","undefined","getDocumentsDirectory"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GAChB,qFAAoF,GACrFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,SAAS,GAAGC,0BAAa,CAACD,SAAS,GACrCC,0BAAa,CAACD,SAAS,GACvB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CAAC,CACF;AAqBE,SAASU,SAASA,CAACC,OAAyB,EAAmB;EACpE,MAAM;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGF,OAAO;EAElC,MAAMG,aAAa,GAAGF,KAAK,CAACG,GAAG,CAAgBC,CAAC,IAAK;IACnD,MAAM;MAAEC,eAAe;MAAE,GAAGC;IAAK,CAAC,GAAGF,CAAC;IAEtC,OAAO;MACLC,eAAe,EAAE,IAAAE,yBAAY,EAACF,eAAe,CAAC,IAAIG,SAAS;MAC3D,GAAGF;IACL,CAAC;EACH,CAAC,CAAC;EAEF,OAAOb,SAAS,CAACK,SAAS,CAAC;IACzB,GAAGG,IAAI;IACPD,KAAK,EAAEE;EACT,CAAC,CAAC;AACJ;AAEO,SAASO,qBAAqBA,CAAA,EAAoB;EACvD,OAAOhB,SAAS,CAACgB,qBAAqB,EAAE;AAC1C"} -------------------------------------------------------------------------------- /lib/module/index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules, Platform, processColor } from 'react-native'; 2 | const LINKING_ERROR = `The package 'react-native-images-to-pdf' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ 3 | ios: "- You have run 'pod install'\n", 4 | default: '' 5 | }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; 6 | const ImagesPdf = NativeModules.ImagesPdf ? NativeModules.ImagesPdf : new Proxy({}, { 7 | get() { 8 | throw new Error(LINKING_ERROR); 9 | } 10 | }); 11 | export function createPdf(options) { 12 | const { 13 | pages, 14 | ...opts 15 | } = options; 16 | const internalPages = pages.map(e => { 17 | const { 18 | backgroundColor, 19 | ...page 20 | } = e; 21 | return { 22 | backgroundColor: processColor(backgroundColor) ?? undefined, 23 | ...page 24 | }; 25 | }); 26 | return ImagesPdf.createPdf({ 27 | ...opts, 28 | pages: internalPages 29 | }); 30 | } 31 | export function getDocumentsDirectory() { 32 | return ImagesPdf.getDocumentsDirectory(); 33 | } 34 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /lib/module/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"names":["NativeModules","Platform","processColor","LINKING_ERROR","select","ios","default","ImagesPdf","Proxy","get","Error","createPdf","options","pages","opts","internalPages","map","e","backgroundColor","page","undefined","getDocumentsDirectory"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AACA,SAASA,aAAa,EAAEC,QAAQ,EAAEC,YAAY,QAAQ,cAAc;AAEpE,MAAMC,aAAa,GAChB,qFAAoF,GACrFF,QAAQ,CAACG,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,SAAS,GAAGP,aAAa,CAACO,SAAS,GACrCP,aAAa,CAACO,SAAS,GACvB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CAAC,CACF;AAqBL,OAAO,SAASQ,SAASA,CAACC,OAAyB,EAAmB;EACpE,MAAM;IAAEC,KAAK;IAAE,GAAGC;EAAK,CAAC,GAAGF,OAAO;EAElC,MAAMG,aAAa,GAAGF,KAAK,CAACG,GAAG,CAAgBC,CAAC,IAAK;IACnD,MAAM;MAAEC,eAAe;MAAE,GAAGC;IAAK,CAAC,GAAGF,CAAC;IAEtC,OAAO;MACLC,eAAe,EAAEhB,YAAY,CAACgB,eAAe,CAAC,IAAIE,SAAS;MAC3D,GAAGD;IACL,CAAC;EACH,CAAC,CAAC;EAEF,OAAOZ,SAAS,CAACI,SAAS,CAAC;IACzB,GAAGG,IAAI;IACPD,KAAK,EAAEE;EACT,CAAC,CAAC;AACJ;AAEA,OAAO,SAASM,qBAAqBA,CAAA,EAAoB;EACvD,OAAOd,SAAS,CAACc,qBAAqB,EAAE;AAC1C"} -------------------------------------------------------------------------------- /lib/typescript/__tests__/index.test.d.ts: -------------------------------------------------------------------------------- 1 | //# sourceMappingURL=index.test.d.ts.map -------------------------------------------------------------------------------- /lib/typescript/__tests__/index.test.d.ts.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/index.test.tsx"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /lib/typescript/index.d.ts: -------------------------------------------------------------------------------- 1 | import type { ColorValue } from 'react-native'; 2 | export type ImageFit = 'none' | 'fill' | 'contain' | 'cover'; 3 | export type Page = { 4 | imagePath: string; 5 | imageFit?: ImageFit; 6 | width?: number; 7 | height?: number; 8 | backgroundColor?: ColorValue; 9 | }; 10 | export type CreatePdfOptions = { 11 | outputPath: string; 12 | pages: Page[]; 13 | }; 14 | export declare function createPdf(options: CreatePdfOptions): Promise; 15 | export declare function getDocumentsDirectory(): Promise; 16 | //# sourceMappingURL=index.d.ts.map -------------------------------------------------------------------------------- /lib/typescript/index.d.ts.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,cAAc,CAAC;AAoBpE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7D,MAAM,MAAM,IAAI,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,UAAU,CAAC;CAC9B,CAAC;AAMF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBpE;AAED,wBAAgB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEvD"} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-images-to-pdf", 3 | "version": "0.2.1", 4 | "description": "Easily generate PDF files from images in React Native.", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "*.podspec", 17 | "!lib/typescript/example", 18 | "!ios/build", 19 | "!android/build", 20 | "!android/gradle", 21 | "!android/gradlew", 22 | "!android/gradlew.bat", 23 | "!android/local.properties", 24 | "!**/__tests__", 25 | "!**/__fixtures__", 26 | "!**/__mocks__", 27 | "!**/.*" 28 | ], 29 | "scripts": { 30 | "test": "jest", 31 | "typecheck": "tsc --noEmit", 32 | "lint": "eslint . --ext .js,.jsx,.ts,.tsx", 33 | "prepack": "bob build", 34 | "release": "release-it", 35 | "example": "yarn --cwd example", 36 | "bootstrap": "yarn example && yarn install && yarn example pods", 37 | "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build" 38 | }, 39 | "keywords": [ 40 | "react-native", 41 | "ios", 42 | "android" 43 | ], 44 | "repository": "https://github.com/Canciller/react-native-images-to-pdf", 45 | "author": "canciller (https://github.com/Canciller)", 46 | "license": "MIT", 47 | "bugs": { 48 | "url": "https://github.com/Canciller/react-native-images-to-pdf/issues" 49 | }, 50 | "homepage": "https://github.com/Canciller/react-native-images-to-pdf#readme", 51 | "publishConfig": { 52 | "registry": "https://registry.npmjs.org/" 53 | }, 54 | "devDependencies": { 55 | "@evilmartians/lefthook": "^1.2.2", 56 | "@commitlint/config-conventional": "^17.0.2", 57 | "@react-native-community/eslint-config": "^3.0.2", 58 | "@release-it/conventional-changelog": "^5.0.0", 59 | "@types/jest": "^28.1.2", 60 | "@types/react": "~17.0.21", 61 | "@types/react-native": "0.70.0", 62 | "commitlint": "^17.0.2", 63 | "del-cli": "^5.0.0", 64 | "eslint": "^8.4.1", 65 | "eslint-config-prettier": "^8.5.0", 66 | "eslint-plugin-prettier": "^4.0.0", 67 | "jest": "^28.1.1", 68 | "pod-install": "^0.1.0", 69 | "prettier": "^2.0.5", 70 | "react": "18.2.0", 71 | "react-native": "0.71.3", 72 | "react-native-builder-bob": "^0.20.4", 73 | "release-it": "^15.0.0", 74 | "typescript": "^4.5.2" 75 | }, 76 | "resolutions": { 77 | "@types/react": "17.0.21" 78 | }, 79 | "peerDependencies": { 80 | "react": "*", 81 | "react-native": "*" 82 | }, 83 | "engines": { 84 | "node": ">= 16.0.0" 85 | }, 86 | "packageManager": "^yarn@1.22.15", 87 | "jest": { 88 | "preset": "react-native", 89 | "modulePathIgnorePatterns": [ 90 | "/example/node_modules", 91 | "/lib/" 92 | ] 93 | }, 94 | "commitlint": { 95 | "extends": [ 96 | "@commitlint/config-conventional" 97 | ] 98 | }, 99 | "release-it": { 100 | "git": { 101 | "commitMessage": "chore: release ${version}", 102 | "tagName": "v${version}" 103 | }, 104 | "npm": { 105 | "publish": true 106 | }, 107 | "github": { 108 | "release": true 109 | }, 110 | "plugins": { 111 | "@release-it/conventional-changelog": { 112 | "preset": "angular" 113 | } 114 | } 115 | }, 116 | "eslintConfig": { 117 | "root": true, 118 | "extends": [ 119 | "@react-native-community", 120 | "prettier" 121 | ], 122 | "rules": { 123 | "prettier/prettier": [ 124 | "error", 125 | { 126 | "quoteProps": "consistent", 127 | "singleQuote": true, 128 | "tabWidth": 2, 129 | "trailingComma": "es5", 130 | "useTabs": false 131 | } 132 | ] 133 | } 134 | }, 135 | "prettier": { 136 | "quoteProps": "consistent", 137 | "singleQuote": true, 138 | "tabWidth": 2, 139 | "trailingComma": "es5", 140 | "useTabs": false 141 | }, 142 | "react-native-builder-bob": { 143 | "source": "src", 144 | "output": "lib", 145 | "targets": [ 146 | "commonjs", 147 | "module", 148 | [ 149 | "typescript", 150 | { 151 | "project": "tsconfig.build.json" 152 | } 153 | ] 154 | ] 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /react-native-images-to-pdf.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' 5 | 6 | Pod::Spec.new do |s| 7 | s.name = "react-native-images-to-pdf" 8 | s.version = package["version"] 9 | s.summary = package["description"] 10 | s.homepage = package["homepage"] 11 | s.license = package["license"] 12 | s.authors = package["author"] 13 | 14 | s.platforms = { :ios => "11.0" } 15 | s.source = { :git => "https://github.com/Canciller/react-native-images-to-pdf.git", :tag => "#{s.version}" } 16 | 17 | s.source_files = "ios/**/*.{h,m,mm,swift}" 18 | 19 | s.dependency "React-Core" 20 | 21 | # Don't install the dependencies when we run `pod install` in the old architecture. 22 | if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then 23 | s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" 24 | s.pod_target_xcconfig = { 25 | "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", 26 | "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", 27 | "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" 28 | } 29 | s.dependency "React-Codegen" 30 | s.dependency "RCT-Folly" 31 | s.dependency "RCTRequired" 32 | s.dependency "RCTTypeSafety" 33 | s.dependency "ReactCommon/turbomodule/core" 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true; 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import type { ColorValue, ProcessedColorValue } from 'react-native'; 2 | import { NativeModules, Platform, processColor } from 'react-native'; 3 | 4 | const LINKING_ERROR = 5 | `The package 'react-native-images-to-pdf' doesn't seem to be linked. Make sure: \n\n` + 6 | Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + 7 | '- You rebuilt the app after installing the package\n' + 8 | '- You are not using Expo Go\n'; 9 | 10 | const ImagesPdf = NativeModules.ImagesPdf 11 | ? NativeModules.ImagesPdf 12 | : new Proxy( 13 | {}, 14 | { 15 | get() { 16 | throw new Error(LINKING_ERROR); 17 | }, 18 | } 19 | ); 20 | 21 | export type ImageFit = 'none' | 'fill' | 'contain' | 'cover'; 22 | 23 | export type Page = { 24 | imagePath: string; 25 | imageFit?: ImageFit; 26 | width?: number; 27 | height?: number; 28 | backgroundColor?: ColorValue; 29 | }; 30 | 31 | interface InternalPage extends Omit { 32 | backgroundColor?: ProcessedColorValue; 33 | } 34 | 35 | export type CreatePdfOptions = { 36 | outputPath: string; 37 | pages: Page[]; 38 | }; 39 | 40 | export function createPdf(options: CreatePdfOptions): Promise { 41 | const { pages, ...opts } = options; 42 | 43 | const internalPages = pages.map((e) => { 44 | const { backgroundColor, ...page } = e; 45 | 46 | return { 47 | backgroundColor: processColor(backgroundColor) ?? undefined, 48 | ...page, 49 | }; 50 | }); 51 | 52 | return ImagesPdf.createPdf({ 53 | ...opts, 54 | pages: internalPages, 55 | }); 56 | } 57 | 58 | export function getDocumentsDirectory(): Promise { 59 | return ImagesPdf.getDocumentsDirectory(); 60 | } 61 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "exclude": ["example"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "react-native-images-to-pdf": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "importsNotUsedAsValues": "error", 11 | "forceConsistentCasingInFileNames": true, 12 | "jsx": "react", 13 | "lib": ["esnext"], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUncheckedIndexedAccess": true, 21 | "noUnusedLocals": true, 22 | "noUnusedParameters": true, 23 | "resolveJsonModule": true, 24 | "skipLibCheck": true, 25 | "strict": true, 26 | "target": "esnext" 27 | } 28 | } 29 | --------------------------------------------------------------------------------