Click here to Skip to main content
Sign Up to vote bad
good
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 - 4:39

Comments
Sergey Alexandrovich Kryukov - 6 Feb '13 - 11:08
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:
_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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,376
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid