Search code examples
dotnetbrowser

How to download a pdf file instead of opening in the browserview using dotnetbrowser


I am trying to download pdf files from the server, but Browser.LoadURL opens the pdf file in BrowserView. I have assigned DownloadHandler to the Browser but it does not fire.


Solution

  • The PDF files are not downloaded because they are opened by a built-in PDF viewer plugin instead.

    To download these files, you need to disable the PDF plugin first.

    To enable/disable a specific plugin you should create your own PluginFilter implementation:

    class CustomPluginFilter : PluginFilter
    {
        public bool IsPluginAllowed(PluginInfo pluginInfo)
        {
            return pluginInfo.MimeTypes.Contains("application/pdf");
        }
    }
    

    This filter is then registered as shown below:

    pluginManager.PluginFilter = new CustomPluginFilter();
    

    The IsPluginAllowed() method is invoked during loading a web page when this web page checks whether a specific plugin is allowed or not.

    After the PDF plugin is disabled, DotNetBrowser will download PDF instead of displaying it.

    The article that describes how to disable the plugin can be found by the following link:

    http://dotnetbrowser-support.teamdev.com/documentation/plugins-manager