Opening
In the previous tutorial on downloading we ended up with a path
variable that has the location of the file that we downloaded.
You may want to open and view the PDF file we downloaded. To do this we need to use a plugin and for this example we'll use @capacitor-community/file-opener
.
First, lets install it:
_10npm install @capacitor-community/file-opener_10npx cap sync
Then in our code we'll call the open
method using the path
variable that has the location of our downloaded PDF.
_10import { FileOpener } from '@capacitor-community/file-opener';_10..._10_10 await FileOpener.open({_10 filePath: path,_10 openWithDefault: true_10 });
On iOS this will open a PDF viewer. On Android this will open a file opener dialog showing applications it can open that will view the PDF (for example Google Drive).
You can try out the open feature in this sample repository.