Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET IIS itextsharp
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:
 
_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 6-Feb-13 5:39am
Comments
Sergey Alexandrovich Kryukov at 6-Feb-13 11:08am
   
Where is your content type?
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
_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();
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100