How to view .pdf file inside a folder in app using file system


#1

it’s bugging me for hours now and I cant get it to work.

I took reference from the following :

https://github.com/Merott/nativescript-pdf-view
Preview/Read a .pdf file inside Nativescript application
https://docs.nativescript.org/cookbook/file-system
File-system: where is the "documents" folder?

heres my current code:
XML

<Page
  xmlns="http://schemas.nativescript.org/tns.xsd"
  xmlns:pdf="nativescript-pdf-view"
  loaded="onLoaded">

<StackLayout class="page-content">
    <pdf:PDFView src="{{ pdfUrl }}"/>
</StackLayout>

</Page>

JS

const AboutViewModel = require("./aboutustp-view-model");
const fs = require("tns-core-modules/file-system");
const documents = fs.knownFolders.currentApp();

var filename = "handbook.pdf";

const filepath = fs.path.join(documents.path, "documents", filename);
console.log("pdf folder path : " + filepath);
this.pdfUrl = filepath;


function onLoaded(args) {
    const component = args.object;
    component.bindingContext = new AboutViewModel();
}

exports.onLoaded = onLoaded;

Question
How can I view/display the PDF itself on the app using this?


Preview/Read a .pdf file inside Nativescript application
#2

Are you sure you have the file at that path?
Are you using Webpack, if yes did you made necessary config changes to keep the file copied during build?
Did you check whether file exists using the exists method in file system?
Do you see any errors in console?