Canciller / react-native-images-to-pdf

Easily generate PDF files from images in React Native.
MIT License
25 stars 10 forks source link

Android failed #15

Closed chzappsinc closed 1 year ago

chzappsinc commented 1 year ago

Summary

Failed to create PDF: Error: Attempt to invoke virtual method 'java.lang.String java.lang.String.replaceFirst(java.lang.String, java.lang.String)' on a null object reference

RN Info

 OS: macOS 13.4
  CPU: (10) arm64 Apple M1 Pro
  Memory: 55.58 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.0
    path: /var/folders/5n/y1bvjv5d5v991f0r3_fwnbbw0000gp/T/yarn--1693897597275-0.348480179943631/node
  Yarn:
    version: 1.22.19
    path: /var/folders/5n/y1bvjv5d5v991f0r3_fwnbbw0000gp/T/yarn--1693897597275-0.348480179943631/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.16.0/bin/npm
  Watchman:
    version: 2022.09.26.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10671973
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.16.1
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Reproducible sample code

  const scanDocument = async () => {
    const outPutDir = `file://${
      RNBlobUtil.fs.dirs.DocumentDir
    }/${generateUuid()}.pdf`;
    const {scannedImages} = await DocumentScanner.scanDocument({
      maxNumDocuments: 10,
    });
    //@ts-ignore
    if (scannedImages?.length > 0) {
      console.log(scannedImages);
      const options = {
        pages: scannedImages,
        outputPath: outPutDir,
      };
      console.log(options);

      createPdf(options)
        .then(path => console.log(`PDF created successfully: ${path}`))
        .catch(error => console.log(`Failed to create PDF: ${error}`));
    }
  };
11:01:41.188
6766
ReactNativeJS
{ pages: [ 'file:///storage/emulated/0/Android/data/com.xxx.app/files/Pictures/DOCUMENT_SCAN_0_20230905_1101416053391029625925290.jpg' ],
  outputPath: 'file:///data/user/0/com.xxx.app/files/943f6a4f-1338-4dac-bfd2-391d0ef53822.pdf' }
11:01:41.195
6766
ReactNativeJS
Failed to create PDF: Error: Attempt to invoke virtual method 'java.lang.String java.lang.String.replaceFirst(java.lang.String, java.lang.String)' on a null object reference

library version: latest

iOS / Android version: 0.72.4

chzappsinc commented 1 year ago

Update

{ pages: 
   [ { imagePath: 'file:///storage/emulated/0/Android/data/com.xxx.app/files/Pictures/DOCUMENT_SCAN_0_20230905_1141025239986292805769924.jpg',
       imageFit: 'fill',
       width: 594,
       height: 843,
       backgroundColor: '#fff' } ],
  outputPath: 'file:///data/user/0/com.xxx.app/files/ecadb3e7-c1b5-46ce-8aff-b5bdc5a6993d.pdf' }
{ pages: 
   [ { imagePath: '/storage/emulated/0/Android/data/com.xxx.app/files/Pictures/DOCUMENT_SCAN_0_20230905_1142425484847059482707656.jpg',
       imageFit: 'fill',
       width: 594,
       height: 843,
       backgroundColor: '#fff' } ],
  outputPath: 'file:///data/user/0/com.xxx.app/files/327d5f73-7566-4237-b6d3-6b20370da9c6.pdf' }

Even options changed, still error

Canciller commented 1 year ago

@chzappsinc I was not able to reproduce this error: https://github.com/Canciller/rn-document-scanner-images-to-pdf-example/blob/01b870e960c215edcf317824784472556afded1d/App.tsx#L9

chzappsinc commented 1 year ago

@chzappsinc I was not able to reproduce this error: https://github.com/Canciller/rn-document-scanner-images-to-pdf-example/blob/01b870e960c215edcf317824784472556afded1d/App.tsx#L9

Same code we are getting this error Android (31)

screen-shot

Canciller commented 1 year ago

Please create a small repository demonstrating the issue. This will help me in fixing the problem.

chzappsinc commented 1 year ago

@Canciller Its working fine on new repo buts its failing on my project,

these are packages i am using

"dependencies": {
    "@backpackapp-io/react-native-toast": "^0.9.0",
    "@gorhom/bottom-sheet": "^4",
    "@react-native-async-storage/async-storage": "^1.19.3",
    "@react-native-community/blur": "^4.3.2",
    "@react-native-community/geolocation": "^3.0.6",
    "@react-native-masked-view/masked-view": "^0.2.9",
    "@react-navigation/devtools": "^6.0.19",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/stack": "^6.3.17",
    "@reduxjs/toolkit": "^1.9.5",
    "axios": "^1.5.0",
    "country-state-city": "^3.2.0",
    "crypto-js": "3.1.9-1",
    "lodash": "^4.17.21",
    "lottie-react-native": "^6.2.0",
    "moment": "^2.29.4",
    "react": "18.2.0",
    "react-native": "0.72.4",
    "react-native-animatable": "^1.3.3",
    "react-native-asset": "^2.1.1",
    "react-native-blob-util": "^0.19.1",
    "react-native-bouncy-checkbox": "^3.0.7",
    "react-native-config": "^1.5.1",
    "react-native-device-info": "^10.9.0",
    "react-native-document-picker": "^9.0.1",
    "react-native-document-scanner-plugin": "^0.9.0",
    "react-native-error-boundary": "^1.2.3",
    "react-native-flipper": "^0.212.0",
    "react-native-gesture-handler": "^2.12.1",
    "react-native-hash": "^3.0.3",
    "react-native-images-to-pdf": "^0.2.0",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.8.2",
    "react-native-localization": "^2.3.2",
    "react-native-maps": "^1.7.1",
    "react-native-pdf": "^6.7.1",
    "react-native-permissions": "^3.8.4",
    "react-native-phone-number-input": "^2.1.0",
    "react-native-progress": "^5.0.0",
    "react-native-radio-buttons-group": "^3.0.3",
    "react-native-razorpay": "^2.3.0",
    "react-native-reanimated": "^3.4.2",
    "react-native-rename": "^3.2.13",
    "react-native-restart": "^0.0.27",
    "react-native-safe-area-context": "^4.7.1",
    "react-native-screens": "^3.24.0",
    "react-native-signature-canvas": "^4.6.1",
    "react-native-skeleton-placeholder": "^5.2.4",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-svg": "^13.13.0",
    "react-native-vector-icons": "^10.0.0",
    "react-native-webview": "^13.5.1",
    "react-redux": "^8.1.2",
    "redux": "^4.2.1",
    "redux-flipper": "^2.0.2",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.4.2",
    "symbol-observable": "^4.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@tsconfig/react-native": "^3.0.0",
    "@types/lodash": "^4.14.197",
    "@types/react": "^18.0.24",
    "@types/react-native-snap-carousel": "^3.8.5",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "babel-plugin-module-resolver": "^5.0.0",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "module-resolver": "^1.0.0",
    "prettier": "^2.4.1",
    "react-devtools": "^4.28.0",
    "react-test-renderer": "18.2.0",
    "tslint": "^6.1.3",
    "tslint-config-prettier": "^1.18.0",
    "tslint-config-standard": "^9.0.0",
    "tslint-eslint-rules": "^5.4.0",
    "tslint-react": "^5.0.0",
    "typescript": "4.8.4"
  },
chzappsinc commented 1 year ago

@Canciller Please check with this repo https://github.com/chzappsinc/image-to-pdf-bug-checking-with-def-config

Using reanimated-babel-plugin

Canciller commented 1 year ago

@chzappsinc can you try with latest version 0.2.1

chzappsinc commented 1 year ago

@Canciller #17 version working fine

Closing bug