top of page
Writer's picturenirav sanghvi

Downloading and Sharing PDFs in React Native

React Native is a popular platform for developing mobile apps. In this post, we will explore how to download and share PDF files in React Native.



Downloading PDFs

To download a PDF in React Native, you can use the react-native-fetch-blob library. This library allows you to download and access files in your React Native app.


Here is an example of how to download a PDF in React Native using react-native-fetch-blob:



import RNFetchBlob from 'react-native-fetch-blob'

const pdfUrl = 'https://example.com/file.pdf'

RNFetchBlob.config({   
  fileCache : true,   
  appendExt : 'pdf' 
}).fetch('GET', pdfUrl) 
.then((res) => {  
 // the temp file path
  console.log('The file saved to ', res.path()) 
})

Sharing PDFs

To share a PDF in React Native, you can use the react-native-share library. This library allows you to share text, images, and files with other apps installed on the device.

Here is an example of how to share a PDF in React Native using react-native-share:



import Share from 'react-native-share'

const pdfPath = '/path/to/pdf.pdf'

Share.open({
  url: 'file://' + pdfPath,
  type: 'application/pdf'
})
.then((res) => console.log(res))
.catch((err) => console.log(err))

That's it! With these libraries, you can easily download and share PDF files in your React Native app.

12 views0 comments

Recent Posts

See All

Comments


bottom of page