我正在使用 react-native-document-picker 来选择 PDF。选择后,我将文件的 URI 传递给 react-native-pdf 的 PDF。它返回给我这个错误,但只在 iOS 上。在 Android 中工作正常。有什么建议么?
ON ERROR --- Error: Load pdf failed. path=file:///private/var/mobile/Containers/Data/Application/250D8D83-5F0F-402C-912B-F1B199551218/tmp/com.yada.nen-Inbox/Bolletta%20Luce%20a2a.pdf
at createErrorFromErrorData (NativeModules.js:152)
at NativeModules.js:104
at MessageQueue.__invokeCallback (MessageQueue.js:442)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:343)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:80
这就是我选择 PDF 的方式:
static pickPDF = async (callBack,goBack=()=>{}) => {
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.pdf],
});
console.log("URI of the uploaded PDF: ", res.uri);
callBack(res.uri, res.name);
} catch (err) {
if (DocumentPicker.isCancel(err) ) {
goBack();
} else {
throw err;
}
}
};
下面是我如何使用 react-native-pdf 显示 PDF:
<Pdf
source={{uri:"file://"+this.state.pdfUri, cache: false}}
horizontal
page={page}
scrollEnabled={false}
onError={(error)=>{
console.log("ON ERROR ---",error);
}}
onPageChanged={this.onPageChanged}
style={flex}
/>