views:

80

answers:

3

Hi,

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.

A: 

You must try Google Docs api.. You just have to implement this api in your website..

Sakti
I can't see anything about either implementing the server side of the protocol or getting a progress report of a download in that documentation. It might be there somewhere, but if so, your answer needs to be much more specific.
David Dorward
i not getting any thing in Google Docs.api.Ok, if we return FileStreamresult , then how to display that in a view to show pdf
Anil
A: 

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
A: 

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.

Marnix van Valen