Skip to main content

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:


_10
npm install @capacitor-community/file-opener
_10
npx cap sync

Then in our code we'll call the open method using the path variable that has the location of our downloaded PDF.


_10
import { 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.