ng2-pdf-viewer
ng2-pdf-viewer copied to clipboard
Rendering pdf from local on mobile
Bug Report or Feature Request (mark with an x
)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [ x ] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request
Hi Vadim I'm having trouble viewing local pdf on mobile. Ionic use and from the web it works perfectly. Do you have any ideas to help me?
this works for me in ionic
import {Component, OnInit} from '@angular/core';
import {File} from '@ionic-native/file/ngx';
@Component({
selector: 'example-app',
template: `
<pdf-viewer [src]="src"
[render-text]="true"
[original-size]="false"
style="width: 100%; height: 100%"
></pdf-viewer>
`
})
export class PdfViewerComponent implements OnInit {
pdfSrc;
src;
constructor(private file: File) {}
ngOnInit() {
this.makeFileIntoBlob(this.pdfSrc);
}
makeFileIntoBlob(_imagePath) {
// INSTALL PLUGIN - cordova plugin add cordova-plugin-file
return new Promise((resolve, reject) => {
let fileName = '';
this.file
.resolveLocalFilesystemUrl(_imagePath)
.then((fileEntry) => {
let {name, nativeURL} = fileEntry;
// get the path..
let path = nativeURL.substring(0, nativeURL.lastIndexOf('/'));
console.log('path', path);
console.log('fileName', name);
fileName = name;
// we are provided the name, so now read the file into
// a buffer
return this.file.readAsArrayBuffer(path, name);
})
.then((buffer) => {
// get the buffer and make a blob to be saved
let imgBlob = new Blob([buffer], {
type: 'application/pdf'
});
console.log(imgBlob.type, imgBlob.size);
debugger
this.src = {data: buffer};
resolve({
fileName,
imgBlob
});
})
.catch((e) => reject(e));
});
}
}
a bit messy, still a work in progress
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.