Have a look at Open a pdf file in ionic
Just declare the function in the answer as a normal function (without using $scope
). This will be undefined during development when the typescript transpiler tries to convert the code to standard JS. To bypass, just do (under the import statements):
declare var windows:any;
declare var cordova:any;
and then in the function before using the window
object:
windows=window;
Of course, this will only work once you build for your target platform and deploy.
There’s also Mozilla Foundation’s PDF.JS. Or their npm package. And a very lightweight variant: ViewerJS.
I’m haven’t tried working with PDF.JS or ViewerJS so I don’t know how to use them. Although, this might be a much better way of doing it if you don’t care about using the in-built PDF viewer on the device.