2

I'm using the object tag to render PDF in HTML, but I'm doing it in MVC like this:

<object data="/JDLCustomer/GetPDFData?projID=<%=ViewData["ProjectID"]%>&folder=<%=ViewData["Folder"] %>"
    type="application/pdf" width="960" height="900">
</object>

and Controller/Action is

    public void GetPDFData(string projID, Project_Thin.Folders folder)
    {
        Highmark.BLL.Models.Project proj = GetProject(projID);
        List<File> ff = proj.GetFiles(folder, false);
        if (ff != null && ff.Count > 0 && ff.Where(p => p.FileExtension == "pdf").Count() > 0)
        {
            ff = ff.Where(p => p.FileExtension == "pdf").ToList();

            Response.ClearHeaders();
            Highmark.BLL.PDF.JDLCustomerPDF pdfObj = new JDLCustomerPDF(ff, proj.SimpleDbID);
            byte[] bArr = pdfObj.GetPDF(Response.OutputStream);
            pdfObj = null;

            Response.ContentType = "application/" + System.IO.Path.GetExtension("TakeOffPlans").Replace(".", "");
            Response.AddHeader("Content-disposition", "attachment; filename=\"TakeOffPlans\"");
            Response.BinaryWrite(bArr);
            Response.Flush();
        }
    }

The problem is, as I'm downloading data first from server and then return the byte data, it is taking some time in downloading, so I want to show some kind of progress to show processing.

Please help me on this.

Marnix van Valen
  • 13,265
  • 4
  • 47
  • 74
Anil
  • 21
  • 2

2 Answers2

0

You may try the following (not tested under all browsers):

<div style="background: transparent url(progress.gif) no-repeat">
    <object 
        data="<%= Url.Action("GetPDFData, new { projID = ViewData["ProjectID"], folder = ViewData["Folder"] }") %>" 
        type="application/pdf" 
        width="640" 
        height="480">
        <param value="transparent" name="wmode"/>
    </object>
</div>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
-2

Unfortunatly, there is no way (afaik) to interact with the Acrobat plugin and see when it's ready to display your PDF document.

There are components available that replace Acrobat and provide a proper Javascript interface. I work for TallComponents on their PDFWebViewer.NET product which will display PDF without any plugins and works with ASP.NET MVC.

You do have some other options though. If you need the progress indicator because the PDF generation is taking longer than you would like you can poll the server for progress using AJAX calls. On the server you would need to have some sort of progress information available that you can return as the result of the ajax call. In the browser you'd use the result to provide progress info to the user. There are several good examples available online (this blog for example). There are also other questions here on SO (for example here) with good pointers to more info.

If the generation process only takes a couple of seconds can you probably get way with showing a busy indicator. That could be as simple as showing a div in your page when you trigger the download from the server.

By the way, if I'm not mistaken you should replace the attachment keyword with inline in the Content-Disposition header. Setting that to attachment will cause the entire PDF to be downloaded before any content is displayed. If you set it to inline, Acrobat will start showing the first page as soon as it has downloaded enough data to do so.

Community
  • 1
  • 1
Marnix van Valen
  • 13,265
  • 4
  • 47
  • 74
  • AFAIK we're not supposed to use this forum to plug our own products. – azarc3 Oct 30 '13 at 18:37
  • I think I made my involvement with the product crystal clear which is inline with the FAQ at the time of writing (3 years ago!). More on that topic on meta [here](http://meta.stackexchange.com/questions/15787/how-do-i-mention-my-own-products-in-answers). Besides that I think I put more than enough relevant information in my answer, it's hardly a promotional plug. Also note that product has been open sourced a year ago. All code is available on codeplex [here](https://pdfwebviewer1.codeplex.com/) and [here](http://webviewer2.codeplex.com/). – Marnix van Valen Oct 30 '13 at 19:09