By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,070 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

Creating PDFs dynamically forces page reload

P: n/a
Hi all,

Im having difficulty serving synamically generated PDFs to clients via
asp.net. Im using crystal reports to generate them. In my page load I have
the following:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument();
rd.Load(file);
for (int i = 1; i < Request.QueryString.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream)rd.ExportToStream

(CrystalDecisions.Shared.ExportFormatType.Portable DocFormat);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer= true;
Response.BinaryWrite(oStream.ToArray());
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Response.End();
}

Although this works fine, Page_load gets called twice before the pdf is
served to the client. Any ideas why this is? For a time intesive reoprt its
pretty critical that its only run the once!

Some notes:

If the Response.BinaryWrite call is commented out, page_load is only called
once, however I get a blank page (as expected).

On the other hand, if Response.End is commented out, then the pdf is served
as a download ("do you wish to open or save etc") with the aspx page as the
default filename - saving this as a pdf results in the report. Again,
page_load is only called the once.

Keeping both calls in displays the pdf correctly, but only after the second
call to page_load. There is a screen reload between the two calls though.

Thanks in advance,

Shak
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
when IE it loads an file that requires a viewer object (like pdf) it may
request more than once. Older versions of IE will actually do 3 requests.

when the browser get a pdf response, it knows it must load acrobat reader,
so it checks again with a request to only fetch the mime-type (of course if
your page doesn't check the request header, it send the whole response.)
after validation the mime-type, it loads acrobat, then gives acrobat the url
of the pdf. acrobat then downloads the file and displays. with more recent
versions of IE, an attempt is made to keep the file in the download cache to
not bother with extra downloads, but does not always work out.

-- bruce

"spammy" <me@privacy.net> wrote in message
news:2p************@uni-berlin.de...
Hi all,

Im having difficulty serving synamically generated PDFs to clients via
asp.net. Im using crystal reports to generate them. In my page load I have
the following:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument();
rd.Load(file);
for (int i = 1; i < Request.QueryString.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream)rd.ExportToStream

(CrystalDecisions.Shared.ExportFormatType.Portable DocFormat);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer= true;
Response.BinaryWrite(oStream.ToArray());
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Response.End();
}

Although this works fine, Page_load gets called twice before the pdf is
served to the client. Any ideas why this is? For a time intesive reoprt its pretty critical that its only run the once!

Some notes:

If the Response.BinaryWrite call is commented out, page_load is only called once, however I get a blank page (as expected).

On the other hand, if Response.End is commented out, then the pdf is served as a download ("do you wish to open or save etc") with the aspx page as the default filename - saving this as a pdf results in the report. Again,
page_load is only called the once.

Keeping both calls in displays the pdf correctly, but only after the second call to page_load. There is a screen reload between the two calls though.

Thanks in advance,

Shak

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.