Search code examples
capacitorcapacitor-plugin

Unable to open PDF files in app view in Capacitor Ionic


import { Plugins } from '@capacitor/core';

const { Browser } = Plugins;

Browser.open({ url: 'http://www.africau.edu/images/default/sample.pdf', windowName:'_self' });

When the url is specified as a link to a website, it works fine but doesnt when specified a PDF. Could someone please suggest if any changes required ? Do i need to specify the rel ? If yes how ? There is no such key to be passed in open call. Response received is 'NO enabled plugin supports this MIME type'.


Solution

  • The Browser plugin from Capacitor should work fine for this. Try without specifying windowName.

    // Capacitor v2
    import { Plugins } from '@capacitor/core';
    const { Browser } = Plugins;
    Browser.open({ url: 'http://www.africau.edu/images/default/sample.pdf'});
    
    // or for Capacitor v3
    import { Browser } from '@capacitor/browser';
    Browser.open({ url: 'http://www.africau.edu/images/default/sample.pdf'});
    

    enter image description here