Click here to Skip to main content
15,903,523 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have an asp.net 3.5 web application using itextsharp (coded in C#) to create a pdf file in the browser. The form allows the user to select a document from a dropdown list which is then outptut as a pdf file in a tab. Another request for a different document opens another new pdf file in a new (different) tab. This works using Visual Studio 2010 but, on the server (IIS 7.0.6), the same document opens in the new tab, no matter which new document is selected.

A snippet of the code:

XML
_DeLetterDocument.Close();
Response.Clear();
Response.Write("<script>");
// The following line did not make a difference:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
// opens PDF in next new tab:
Response.Write("window.open('Pdf/DELetterDoc.pdf');");
Response.Write("</script>");


What am I missing?
Any help is greatly appreciated.
Roman
Posted
Comments
Sergey Alexandrovich Kryukov 6-Feb-13 11:08am    
Where is your content type?
—SA

1 solution

I found and succesfully tested the following code on IIS 7 (a different Pdf file is opened each time I choose a different document). However I am not sure how to generate the Pdf file into a new tab each time a new document is requested. I prefer a new tab instead of having the Pdf file open in the same window as the form. Any ideas? (Thank you in advance.)

To avoid the original problem on IIS, MemoryStream was used:
C#
_DocMemoryStream = new MemoryStream();
_Document = new Document(PageSize.A4, 1, 1, 10, 10);
 _PdfWriter = PdfWriter.GetInstance(_Document, _DocMemoryStream);
_Document.Open();

// Update _Document content here...

Response.Clear();
Response.ContentType = "application/pdf";
_DeLetterDocument.Close();
//Write the document to the response stream:
_PdfWriter.Flush();
Response.OutputStream.Write(_DocMemoryStream.GetBuffer(), 0, _DocMemoryStream.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.End();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900