wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.58k stars 540 forks source link

Base64 PDF on iOS error #739

Open giovanijfc opened 1 year ago

giovanijfc commented 1 year ago

What react-native version are you using? 0.68.7

What react-native-pdf version are you using? 6.6.2

What platform does your issue occur on? (android/ios/both) ios

Describe your issue as precisely as possible : I am adapting my app to work on iOS, currently I only use React Native for Android.

In my PDFViewer component, I have the use of PDFs in base64 and also URLs. However, when I use base64 on iOS, I receive the following error:

[Error: File '/Users/admin/Library/Developer/CoreSimulator/Devices/396FECD1-3C30-4CB4-A364-B40349C0B842/data/Containers/Data/Application/E7B94EF8-20BB-4DAB-BF80-DEE85EB1D4AA/Library/Caches/17ae4692b07f2175cab6ba4b1fbf3bb8cee1a096.pdf' could not be written.]

When using a PDF URL, I have no problems. To reproduce, you can try using a PDF in base64 on iOS. I am testing it on the simulator as I don't have a physical device.

Join a screenshot or video of the problem on the simulator or device? ...

Show us the code you are using?


export const PREFIX_BASE_64_PDF = 'data:application/pdf;base64,'

export const PDFViewer = (params: { uri: string }) => {
  return (
    <PDF
      onError={e => console.log('error', e)}
      renderActivityIndicator={progress => (
        <AreaCenter>
          <LineProgress progress={progress} />
        </AreaCenter>
      )}
      source={{
        uri: `${params.uri.includes('http') ? '' : PREFIX_BASE_64_PDF}${
          params.uri
        }`
      }}
    />
  )
}
fonderkin commented 1 year ago

same problem

iOS 16.4

"react": "18.2.0",
"react-native": "0.71.8",
"react-native-blob-util": "^0.18.3",
"react-native-pdf": "^6.7.1",
fonderkin commented 1 year ago

Problem in the library react-native-blob-util

I create issue

Phips0812 commented 11 months ago

Anyone got this working already?

Phips0812 commented 9 months ago

Got it working with: https://github.com/RonRadtke/react-native-blob-util/issues/267#issuecomment-1831006781

Removing newlines from the base64 string did the trick:

pdfString.replace(/\r?\n|\r/g, '');