nativescript-pdf-view icon indicating copy to clipboard operation
nativescript-pdf-view copied to clipboard

Webpack bundling does not working with local PDF files

Open anki247 opened this issue 6 years ago • 4 comments

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

anki247 avatar Aug 22 '18 18:08 anki247

@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?

seveneye avatar Jan 21 '19 08:01 seveneye

unfortunately not...

anki247 avatar Apr 15 '19 19:04 anki247

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 avatar Apr 20 '19 18:04 blipk

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.

blipk avatar Apr 20 '19 19:04 blipk