I want to download list of base64 images as single pdf file in to my device.I have implemented following for that, issue is download is working correctly but can’t open the downloaded file getting “Cannot display PDF(file_name.pdf is of invalid format)”
Code:
const externalStorageDirectory =
Platform.OS === 'android'
? RNFS.ExternalStorageDirectoryPath
: RNFS.DocumentDirectoryPath;
const imageArray = downloadImages.map(item => item.image);
const downloadPdf = async () => {
try {
const pdfContent = imageArray
.map(base64Image => `<img src=${base64Image} />`)
.join('');
const downloadPath = externalStorageDirectory + '/downloaded.pdf';
await RNFS.writeFile(downloadPath, pdfContent);
console.log('PDF downloaded successfully:', downloadPath);
} catch (error) {
console.error('Error downloading PDF:', error);
}
};
downloadPdf();
Can someone help me to solve this issue ?