View pdf from remote link

#1

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

#2

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>
3 Likes
How to open a remote PDF with Ionic?
#3

This doesnt work in android device :frowning:

#4

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.

1 Like
#5

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.

#6

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

#7

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

#8

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

#9

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