2

i'm using react-native-document-picker to select a PDF. After the selection i'm passing the URI of the file to PDF of react-native-pdf. It returns me this error, but only on iOS. In Android works fine. Any suggestions?

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

And this is how i'm picking the 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;
        }
    }
};

And below is how i'm showing the PDF with react-native-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}
                />
denno
  • 129
  • 1
  • 4
  • 17

1 Answers1

0

Its just because your pdf file have space in between name remove space and then check it works for me.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 17 '21 at 21:11