我使用react-native
创建了一个应用程序,并从API获取了一些base64数据。 我想将base64数据转换为pdf格式。 如果您有任何想法,请帮助我。 谢谢。
我使用react-native
创建了一个应用程序,并从API获取了一些base64数据。 我想将base64数据转换为pdf格式。 如果您有任何想法,请帮助我。 谢谢。
{uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."}
let fPath = Platform.select({
ios: fs.dirs.DocumentDir,
android: fs.dirs.DownloadDir,
});
fPath = `${fPath}/pdfFileName.pdf`;
if (Platform.OS === PlatformTypes.IOS) {
await fs.createFile(fPath, base64Data, "base64");
} else {
await fs.writeFile(fPath, base64Data, "base64");
}
// RNFetchBlob can be used to open the file
fs
依赖从哪里来的? - Martinocomreact-native-fs
的东西,你可以检查一下它是否仍然存在。 - senthil balajiimport RNFS from 'react-native-fs';
,在此之后,我可以直接使用 await RNFS.writeFile(path, fileContent, 'base64');
。提醒:在iOS和Android上设置权限!对于“仅预览,稍后复制”的方法,可以使用 RNFS.DocumentDirectoryPath
。要将文件复制到下载文件夹中,我使用了 import { FileSystem } from 'react-native-file-access';
中的 await FileSystem.cpExternal(fullPath, fileName, 'downloads');
。为了预览PDF,我使用了 import FileViewer from 'react-native-file-viewer';
中的 await FileViewer.open(fullPath)
。 - Martinocom