🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Matt_N_Morton Thu, 06 Jul 2006 16:18
Unable to read streamed PDF content embedded in broswer
#15634
Author: Matt_N_Morton
Date: Thu, 06 Jul 2006 16:18
34 lines
2232 bytes
I have a web application that, for security reasons, writes PDF content to the Response object, rather than having the browser redirect to the source file. This works great for users with most browser/Adobe reader combinations. However, with some(specifically IE5 on WIN2000 with Adobe 6.x), the browser window is empty. And if you open Reader directly, you see the pdf. I figure there is some piece of Content Header that I'm omitting, that's preventing the binary stream from being displayed in the browser. This is what I have:

int bufferSize = 1024; // Size of the buffer.
byte[] outbyte = new byte[bufferSize]; // The byte[] buffer to be filled.
long retval; // The bytes returned

Response.AddHeader("Content-Type", "application/PDF");
Response.AddHeader("Content-Length", new FileInfo(fileName).Length.ToString() );
Response.AddHeader("Content-Disposition", "inline; filename=fileName.PDF");

// need a FileStream //
using(FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
    do
    {
        // fill the buffer with data //
        retval = fileStream.Read(outbyte, 0, bufferSize);

// make sure we read some data //
        if (retval != 0)
        {
            // output to the writer //
            Response.OutputStream.Write(outbyte, 0, (int)retval);
        }
    }
    while (retval > 0); // any more data to read?

// write the leftovers //
    Response.OutputStream.Write(outbyte, 0, (int)retval);
}
Response.Flush();

I was hoping that someone may be able to provide the Content headers that I'm missing. Any help would be greatly appreciated.
Thanks.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads