Canciller / react-native-images-to-pdf

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

Unable to create the pdf from the image [Error: The file “xxx.jpg” couldn’t be opened.] #25

Open Deepak-147 opened 9 months ago

Deepak-147 commented 9 months ago

Summary

Unable to create the pdf from the image

Steps to reproduce

import { createPdf } from 'react-native-images-to-pdf';
import RNFS from 'react-native-fs';
const DIR_LOC = RNFS.DocumentDirectory + "/myFolder/"

const options = { 
  pages: [ { imagePath: DIR_LOC + "xxx.jpg" }], // File exists at this location
  outputPath: DIR_LOC + "file.pdf"
};

createPdf(options)
 .then((path) => 
    console.log(PDF created successfully: ${path})) 
 .catch((error) => 
   console.log(Failed to create PDF: ${error})
);

Environment info

npx react-native info output:

System:
  OS: macOS 14.2.1
  CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Memory: 85.68 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: ~/.nvm/versions/node/v18.19.0/bin/node
  Yarn: Not Found
  npm:
    version: 7.15.1
    path: ~/Personal/Work/Projects/Mobility/Nexus/Nexus/MobileTemplate/node_modules/.bin/npm
  Watchman:
    version: 2023.09.25.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20
    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.73.2
    wanted: 0.73.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

library version: 0.2.1

iOS: 17.3 Device: iPhone XR

zj-landeed commented 3 months ago

pass the base64 data into imagePath instead of the path and it will work. Format here: https://github.com/Canciller/react-native-images-to-pdf?tab=readme-ov-file#valid-imagepath