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()
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?
Thanks for your consideration.
You can use the following code to avoid your code be executed twice:
Pdf pdf = new Pdf();
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.
It’s still unclear why this is so. Any further information on this would be great. Thanks.
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.
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”;
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