open pdf is in new tab
I made pdf file in iTextSharp library. I use following code. this pdf is automatic save in file folder. but i want pdf is open is in new tab. How开发者_StackOverflow it is possible.
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
using (iTextSharp.text.Document doc = new iTextSharp.text.Document())
{
using (iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, ms))
{
doc.Open();
doc.Add(new iTextSharp.text.Paragraph(lblMessage.Text.ToString()));
doc.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Receipt3.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(ms.ToArray());
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
You might want to consider the <a>
target attribute. You can use this to open the PDF in a new Window, perhaps using something like:
<a href="GeneratePdf.ashx?somekey=10" target="_blank">
Update- as you have now said that you don't mind whether it is in a browser window or not, my preferred technique is to change the content disposition to attachment as per MercerTraieste answer.
If you are using ASP.NET, it is definitely a good idea to consider writing a custom HttpHandler to stream the PDF for you.
精彩评论