PDF JS, from file location

2.1k Views Asked by At

I have successfully set up using the viewer with the following code:

 protected void btnShowPDFS_OnClick(object sender, EventArgs e)
 {
    // Display all files.
    string[] files = Directory.GetFiles(@"D:\Reports\2014\July\", "*.PDF");

    var pdfNames = new List<string>();
    foreach (string file in files)
    {
        string fileName = Path.GetFileName(file);

        string queryString = "/web/viewer.html?file=" + System.Web.HttpUtility.UrlEncode("../July/" + fileName);
        pdfNames.Add(queryString);

    }
    listView.DataSource = pdfNames;
    listView.DataBind();

  }

Now, this all works fine if all my PDF's are in a folder within the website (i.e localhost). However, how do i point the view to either a network share, or just another folder on the same machine, but outside of IIS?

1

There are 1 best solutions below

0
On

A browser's XMLHttpRequest might have a restrictions for local files access (Firefox has more relaxed policy for local file than other browsers).

PDF.js is using XHR; and PDF.js also allows "load" files from a typed array (Uint8Array). You can use the latter in your solution. Notice the Internet Explorer (WebBrowser control) has window.external that can be used to transmit the data from the host application, see http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting(v=vs.110).aspx