React Native Error: RNHTMLtoPDF error: Could not create folder structure
React Native Error: RNHTMLtoPDF error: Could not create folder structure
开发环境
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
我无法在 ANDROID API 级别 29 中制作 PDF。它在 API 级别 28 中工作正常。
所以我将 RN 版本从 0.63.2
从 0.62.2
和 Gradle 3.5.3
降级到 3.5.2
根据这个问题https://github.com/christopherdro/react-native-html-to-pdf/issues/189
也关注了https://github.com/christopherdro/react-native-html-to-pdf/issues/149
这个也是。它说权限错误所以在 componentDidMount()
我添加了以下行
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
但还是没有运气。
我收到以下错误。
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]
这是我正在使用的库https://github.com/christopherdro/react-native-html-to-pdf
我从 this link
找到了解决方案
如果您发现您的应用无法创建任何文件或文件夹,您应该添加
android:requestLegacyExternalStorage="true" in your `<application>` in `AndroidManifest.xml`
了解更多详情Official Link and
记住:我使用的是 React Native,并且仅在 Android API 29 及更高版本中我陷入了这个问题。
我也遇到了这个问题,经过一番研究,我解决了这个问题,
“目录名称必须与您设备中存在的目录(文件夹)相同,如果您想创建自定义目录,那么由于文件结构或某些本机权限,如果自定义目录名称不起作用,那么它可能会或可能不会在您的设备中工作您必须在目录选项中指定 'Documents' 或 'Download'"
注意:
示例:
async createPDF() {
let options = {
html: '<h1>Export PDF</h1>',
fileName: 'MyPdf',
directory: 'Documents', //or Download
};
let file = await RNHTMLtoPDF.convert(options)
alert(file.filePath);
}
开发环境
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
我无法在 ANDROID API 级别 29 中制作 PDF。它在 API 级别 28 中工作正常。
所以我将 RN 版本从 0.63.2
从 0.62.2
和 Gradle 3.5.3
降级到 3.5.2
根据这个问题https://github.com/christopherdro/react-native-html-to-pdf/issues/189
也关注了https://github.com/christopherdro/react-native-html-to-pdf/issues/149
这个也是。它说权限错误所以在 componentDidMount()
我添加了以下行
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
但还是没有运气。 我收到以下错误。
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]
这是我正在使用的库https://github.com/christopherdro/react-native-html-to-pdf
我从 this link
找到了解决方案如果您发现您的应用无法创建任何文件或文件夹,您应该添加
android:requestLegacyExternalStorage="true" in your `<application>` in `AndroidManifest.xml`
了解更多详情Official Link and
记住:我使用的是 React Native,并且仅在 Android API 29 及更高版本中我陷入了这个问题。
我也遇到了这个问题,经过一番研究,我解决了这个问题, “目录名称必须与您设备中存在的目录(文件夹)相同,如果您想创建自定义目录,那么由于文件结构或某些本机权限,如果自定义目录名称不起作用,那么它可能会或可能不会在您的设备中工作您必须在目录选项中指定 'Documents' 或 'Download'"
注意:
示例:
async createPDF() {
let options = {
html: '<h1>Export PDF</h1>',
fileName: 'MyPdf',
directory: 'Documents', //or Download
};
let file = await RNHTMLtoPDF.convert(options)
alert(file.filePath);
}