Emulator console shows
“[error] - Error in SitewaertsDocumentViewer.viewDocument(): {“message”:“invalid file url ‘${filePath}/1.pdf’ or no viewer for mime type ‘application/pdf’”,“details”:{“status”:0}}“
openList() {
const var = this.httpClient.get(’/assets/IOA_esp.pdf’).subscribe((x)=>{
this.document.viewDocument(xxxx, 'application/pdf', this.options);
});
You cannot use var as variable name - nor should you be using it to declare a variable. Next, assigning the http.get to a variable will not yield the content but in this case a completed subscription.
At least you should do a console.log on x to see the content before passing on.
Next, the error might indicate something weird - sometimes like CORS, but you are referring to localhost? On what device are you running?
Console of Chrome results: “null/assets”. iOS emulator results: “[error] - Error in SitewaertsDocumentViewer.viewDocument(): {“message”:“invalid file url ‘${filePath}/1.pdf’ or no viewer for mime type ‘application/pdf’”,“details”:{“status”:0}}“
Using
openList() {
const t = this.httpClient.get(’/assets/1.pdf’).subscribe((x)=>{
console.log(x);
});
I solved using Document-Viewer (Document Viewer | Cordova Plugin Document Viewer for PDF Files).
The problem was in the path of the file, which should be this.document.viewDocument(’…/…/…/assets/file.pdf’, ‘application/pdf’, options); NOT this.document.viewDocument(’/assets/file.pdf’, ‘application/pdf’, options);
[error] - Error in SitewaertsDocumentViewer.viewDocument():
{"message":"invalid file url 'capacitor://localhost/assets/file.pdf' or
no viewer for mime type 'application/pdf'","details":{"status":0}}
Document Viewer works when I use iPhone emulator and absolute path from file (such as /Users/usuer/app/src/assets/file.pdf), showing that Document Viewer is working.