Merott / nativescript-pdf-view

A basic PDF viewer plugin for NativeScript. Now maintained by @madmas: github.com/madmas/nativescript-pdf-view
Other
32 stars 35 forks source link

Webpack bundling does not working with local PDF files #35

Open anki247 opened 6 years ago

anki247 commented 6 years ago

Showing local files work as expected, but not if you bundle the project with Webpack. Online PDF works also with bundle...

seveneye commented 5 years ago

@anki247 same with me. i was able to configure webpack to include pdf files and I can get the file using the filesystem. However when setting it to the src nothing happens, online url works tho. Have you got any workarounds?

anki247 commented 5 years ago

unfortunately not...

blipk commented 5 years ago

there is this fork here: https://www.nsplugins.com/plugin/nativescript-pdf-view-bundling-enabled https://github.com/Essent/nativescript-pdf-view but some of it is outdated compared to this main branch. @Merott any chance of a merge for the feature?

blipk commented 5 years ago

Okay that fork didnt work and seems it's changes may have been merged anyway, but I found this solution:

First I had to make sure the files where being included by adding my resources folder to webpack.config.ts (you could also add |pdf to the previous line to include all pdfs)

new CopyWebpackPlugin([
    { from: "fonts/**" },
    { from: "**/*.+(jpg|png)" },
    { from: "resources/**/*" },
    { from: "assets/**/*" },
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),

Then I used the following to get a direct path to the PDF and bound that to the PDFView component

import { knownFolders, Folder, File, path } from "tns-core-modules/file-system";
this.appFolder = knownFolders.currentApp();
this.FAQPDF = path.normalize(this.appFolder.path + "/resources/myfile.pdf");

<PDFView :src="FAQPDF" @onLoad="voidEvent"></PDFView>

Hope this helps.