5

Development Environment

System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 248.71 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 13.2.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5900203
    Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
  Languages:
    Java: 13.0.1 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found

I am not able to make PDF in ANDROID API LEVEL 29. It is working fine in API LEVEL 28. So I downgraded RN version from 0.63.2 from 0.62.2 and Gradle 3.5.3 to 3.5.2 according to this issue https://github.com/christopherdro/react-native-html-to-pdf/issues/189

also followed https://github.com/christopherdro/react-native-html-to-pdf/issues/149 this too. It says Permission error so inside componentDidMount() I have added following line

PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)

But still no luck. I am getting following error.

Possible Unhandled Promise Rejection (id: 0):
Error: RNHTMLtoPDF error: Could not create folder structure.
promiseMethodWrapper@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2214:45
createPDF$@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:136885:88
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26640:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26813:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26640:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26713:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26743:19
tryCallTwo@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:28610:9
doResolve@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:28774:25
Promise@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:28633:14
callInvokeWithMethodAndArg@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26742:33
enqueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26747:157
async@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26764:69
createPDF@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:136851:42
requestReadPermission$@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:136835:33
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26640:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26813:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26640:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26713:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:26723:21
tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:28601:16
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:28702:27
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:32141:17
_callImmediatesPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:32177:19
callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:32395:33
callImmediates@[native code]
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2719:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2505:34
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2702:15
flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2504:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

This is library which I am using https://github.com/christopherdro/react-native-html-to-pdf

Dharmik
  • 2,325
  • 3
  • 27
  • 37

2 Answers2

3

I found solution from this link

If you find out that your app is not able to make any file or folder you should add

android:requestLegacyExternalStorage="true" in your `<application>` in `AndroidManifest.xml`

for more details Official Link and Other StackOverflow Question Answsers

Remember: I am using React Native and only in Android API 29 and above I stuck in this issue.

Dharmik
  • 2,325
  • 3
  • 27
  • 37
1

I was also facing that problem, after some researching, I solve that problem, "Directory name must be same as the directory(folder) present in you device, if you want to make custom directory then it may or may not work in you device because of the file structure or some native permission if custom directory name not work then you have to specify 'Documents' or 'Download' at directory option"

Note: you can follow doc for IOS

Example:

async createPDF() {
  let options = {
    html: '<h1>Export PDF</h1>',
    fileName: 'MyPdf',
    directory: 'Documents', //or Download
  };
  let file = await RNHTMLtoPDF.convert(options)
  alert(file.filePath);
}
Vishal Pawar
  • 1,447
  • 8
  • 10
  • Yes, but we might want to make directory if its not exist. on some device there is docs directory and others have documents. so can't fix this – Dharmik Sep 12 '20 at 05:35