【发布时间】:2016-07-29 12:21:07
【问题描述】:
我正在使用 react-native-pdf-view 库,但在使用 pdf 填充 PDFView 时遇到问题。
我的项目的工作原理是我从服务器接收 base64 pdf,然后使用库 react-native-fs 将其保存到 android 文件系统,如下所示:
(这很好用)
saveFile(filename){
var base64Image = this.state.imageBase64;
// create a path you want to write to
var path = RNFS.DocumentDirectoryPath + '/' + filename;
// write the file
RNFS.writeFile(path, base64Image, 'base64').then((success) => {
console.log('FILE WRITTEN!');
this.setState(
{pdf_dirPath: path}
);
this._display_fileAttachment()
})
.catch((err) => {
console.log(err.message);
});
}
然后我尝试使用以下内容填充 pdf 视图:
<PDFView
ref={(pdf)=>{this.pdfView = pdf;}}
src={"path/To/base64/pdf"}
style={styles.pdf}
/>
问题
react-native-pdf-view 是否必须获取文件位置,或者是否可以获取 base64 pdf 或 blob。
如果它可以采用 base64 或 blob,请解释或提供有关如何执行此操作的示例代码。
谢谢
Nb:This StackOverflow question 非常相似,但我需要知道如何以何种形式从文件系统中保存或检索 base64 以及如何填充 pdf。
【问题讨论】:
-
看起来像source-code,它似乎不接受base64,你必须提供一个路径。为了解决这个问题,我会
console.logpath/to/pdf确认它已保存并且是一个好的 PDF。 -
@Kyle Finley 感谢您指出这一点。问题似乎是保存文件。查看这篇文章了解更多详情。 stackoverflow.com/questions/38662309/… 谢谢。
标签: pdf react-native pdf-viewer react-native-android react-native-fs