将应用程序中存储的本地pdf读取到Nativescript中的pdf查看器

时间:2019-04-27 09:22:04

标签: nativescript

我正在使用nativescript-pdf-viewer(https://github.com/Merott/nativescript-pdf-view)来查看在线和本地存储的pdf。

我在github和文档https://docs.nativescript.org/ns-framework-modules/file-system中尝试了几个答案,但是主题似乎都不起作用。我有如下路径的输出:

const currentAppFolder = fileSystemModule.knownFolders.currentApp()
const filePath = fileSystemModule.path.join(currentAppFolder.path, "assets", "test.pdf")
this.pdfPath = filePath 

可以获取路径,但是当绑定到PdfView元素的src时,它什么也不返回(不显示)。

我正在为此项目使用Nativescript-Vue。

1 个答案:

答案 0 :(得分:0)

问题全在于我的Webpack配置。在此代码段中,

// webpack.config.js

 // Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin([
 { from: "**/*", context: "assets" },
 ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),

事实证明,您放置在根路径/app/assets/pdf(以及该资产文件夹中的其他文件)中的内容,将反映在本地平台文件platforms/android/app/src/main/assets/app/{the files/folders inside your assets}

因此,要使用Nativescript的文件系统来调用它,

 const currentAppFolder = fs.knownFolders.currentApp()
 const filePath = fs.path.join(currentAppFolder.path, 'pdf', 'eq.pdf')
 //console.log('PDF', fs.File.exists(filePath))
 this.pdfPath = filePath

我创建了一个名为Nitibo的本机脚本类型模板的模板。 在https://gitlab.com/nativescript-projects/nitibo

签出
相关问题