views:

138

answers:

1

I have a classic asp page which generates a PDF serves it to the browser. What I would like to do is have a loading page which loads the PDF in the background before serving it to the browser when this is complete, essentially adding a nice page indicating to the user that something is happening.

I have looked at things like the Yahoo progress bar but I didn’t see any way of then serving the pdf up.

Anybody have any suggestions? I'm sure this must have been done before.

A: 

I found a solution for this situation that uses iframes. It's not classic asp, but I don't see why it wouldn't work. Here's the article I found.

EDIT: added code.

Container page called by your application:

<head runat="server">
    <script language="javascript" type="text/javascript">
        function BuildPDF() {
            var iframe = document.createElement("iframe");
            iframe.src = "BuildPDF.asp?" + <whatever args you need>;
            iframe.style.display = "none";
            document.body.appendChild(iframe);
        }

        function UpdateProgress(message) {
            document.getElementById('txtStatus').value = message;
        }

        function SetDisplayFileName(fileName) {
            var viewFrame = document.createElement("iframe");
            viewFrame.id = "viewFrame";
            viewFrame.src = "WhateverTheNameOfYourPDFViewASPPageAndArgs";
            viewFrame.style.width = '100%';
            viewFrame.style.height = document.documentElement.clientHeight - 20;
            document.body.appendChild(viewFrame);
        }

        function ResizeFrame() {
            var viewFrame = document.getElementById("viewFrame");
            viewFrame.style.height = document.documentElement.clientHeight - 20;
        }
    </script>
</head>
<body onload="BuildPDF();" onresize="ResizeFrame();">
    <form id="form1" runat="server">
    <input type="text" id="txtStatus" style="width:80%; font-family: Tahoma, Verdana; font-size: small; font-weight: bold;" readonly="readonly" />
    <br />    
    </form>
</body>

Then, somewhere in your BuildPDF.asp, you have a function something like this that you can call anytime you want to update the status message:

function UpdateProgress(message)
    Response.Write("<script>parent.UpdateProgress('" & message & "');</script>")
    Response.Flush()
end function

The page you have referenced in the "viewFrame" is your page that streams the ContentType "application/pdf." Again, I did this in ASP.Net, but I see no reason why it wouldn't work in classic ASP.

AJ
Thats the right idea however the classic asp page that is being called returns Response.ContentType = "application/pdf", it wouldn't be possible to output script tags into this page.
Anthony
In this situation, you'd have three pages: a "container" page with two iframes, and a page for each iframe. One iframe page would have your progress updates. The other would have your Response.ContentType="application/pdf".
AJ