View pdf from remote link

How do i view pdf file from url (internet)? can you help me? thanks

in Your .ts file use this code.

import { DomSanitizer} from '@angular/platform-browser';

@Component({
  ...
})
export class XYZ {
    pdfLink:any;
    constructor(private sanitizer: DomSanitizer) {
        this.pdfLink = this.sanitizer.bypassSecurityTrustResourceUrl('http://docs.google.com/gview?embedded=true&url='+YOUR_PDF_URL_GOES_HERE);
    }
}

in your HTML file


<iframe *ngIf="pdfLink" [src]="pdfLink" width="100%" height="100%" frameborder="0" ></iframe>
6 Likes

This doesnt work in android device :frowning:

I used https://github.com/VadimDez/ng2-pdf-viewer this plugin will allow you to render a canvas with the pdf file, works good for me. And to add some of other capabilities like zoom, I use https://github.com/leonardosalles/ionic2-zoom-area.

2 Likes

It works in every android and iphone devices. I have checked it and it’s also running in my live app.
Maybe you are missing something.

it is not working in device. through cors error in console log.

for CORS related issues,CORS has to configure from Server end.Just check with your backend team.

Now I am downloading and view pdf in available pdf viewer in phone.

I can confirm that this method (iframe method) works in debug mode, with IonicDevApp and on Android devices, thank you.

I’ve tried ng2-pdf-viewer as suggested by @leonardoss but I’m not able to make it work on my app. I’ve not found an example that explains how to use this library with Ionic3.

Claudio

Its working fine with pdf links files hosted on firebase but when i add gdrive pdf file link it only show html document as i attached the document