Free Support Forum -

Pdf.Save(HttpResponse) code generates the PDF twice

We use this code to override the Response object in order to produce a PDF in a popup JavaScript window:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
lReportStruct = CType(Session(“REPORT_DESCRIPTION_OBJECT”), ReportDescStructure)
Dim objReport As New SM_Reporter(lReportStruct)
objReport.Header = lReportStruct.Report_Title
objReport.Orientation = lReportStruct.Report_Orientation
Dim objPdf As Pdf = objReport.GetPdf()
End Sub

The problem is that when we debug, we see that this code is being executed twice (!).

Do you have any code examples of using the Pdf.Save(HttpResponse) method to return a PDF to the browser without it being generated twice?


Dear Edward,

Thanks for your consideration.

You can use the following code to avoid your code be executed twice:


Pdf pdf = new Pdf();

[Visual basic]

Dim pdf As Pdf = New Pdf()

I used the above code but it still executes twice.

You can recreate this by using this example:

Just unzip this in a web directory with WRITE rights and run it in your browser.

After running it, you will see a file called “DebugOutput.htm” in the root directory
which will have two entries similar to these:

18.05.2004 15:39:12 [WAS HERE]
18.05.2004 15:39:17 [WAS HERE]

This shows that the execution created the report twice. You can even see in the popup window how after 5 seconds it blinks and the next generation of the report begins. Then when the second generated report is finished, it is displayed.

If you use this code in Visual Studio .NET, you can debug and see how it runs through the overwrite render method twice and even skips over the Response.End().

How can we get this so that it only generates the PDF once?


OK, we found out what was causing this:

1. The above code will post twice ONLY if you have your browser settings set to:

Tools | Internet Options | Settings | Check for newer versions of stored pages: Never

If you have it on “Every visit to the page” then it will work fine.

2. This is only true if the .aspx page is a pop-up page inside a javascript window, otherwise it will work fine with both settings.

It’s still unclear why this is so. Any further information on this would be great. Thanks.


Dear Edward,

Thanks for your consideration.

Thanks for your information. We will try to find the reason and give further information.

We have found that adding this line:


enables the report to be generated only once regardless of the browser settings.

This is our current solution to this problem.


Although the above line:


forces the page to only produce the PDF once, which solved our problem, it also causes the following problem:

When your browser settings (IE) are on “Every visit to page”, then the browser will pop up a Open/Save dialog instead of displaying the PDF in the pop-up window.

We still haven’t resolved this.

If anyone has any code examples to display a PDF inside a javascript window which works no matter how the Internet Explorer cache settings are set, we would love to have this code. Perhaps there is a totally different way of doing this. (If it is NOT a “” Javascript window then everything works, but this is not an option for us, it has to be in a pop-up Javascript window).




This is what we are doing and I wonder if you have tried adding “Content-Disposition” to the response header. This worked for us when we were getting the Open/Save dialog box. Let me know…


Response.ContentType = “application/pdf”;

Response.AddHeader(“Content-Disposition”, “inline;filename=report.pdf”);

m_pdf.Save(“report.pdf”, Aspose.Pdf.SaveType.OpenInBrowser, Response);

If you put your code to create the pdf in the page_load between If IsPostback then… End If and in the htmlcode for the page you add a script after the form closing tag that submits the form like this:

then after the first cal of the form the submit will be executed and next to that the pdf is created. The response is ended with response.end. Works well on a non secure site.
On a secure site (SSL) an error is raised for non secure items on the page. Seems that somewhere while saving the pdf to the response a non secure item is loaded. (maybe from adobe ) but I haven’t solved this prblem yet. I anyone knows how to solve this??

Frans van Luit