|
-
February 9th, 2010, 04:45 AM
#1
Open PDF in new window
Hello,
I tried all the following methods to open my newly created PDF in a new window but none of them worked! I added break points on all the statements in the "finally" block and managed to successfully jump to the end before then being redirected to my error page. Can you spot the mistake?
Code:
public void CreatePDF()
{
doc = new Document(PageSize.A4, 80, 50, 30, 65);
string PDFpath = Server.MapPath("~/test.pdf");
try
{
FileStream stream = new FileStream(PDFpath, FileMode.Create);
writer = PdfWriter.GetInstance(doc, stream);
doc.Open();
FormatPDF();
// First read the PDF before stamping it
PdfReader pdfReader = new PdfReader(Request.MapPath("~/test.pdf"));
PdfStamper pdfStamper = new PdfStamper(pdfReader, Response.OutputStream);
pdfStamper.FormFlattening = true;
// Close the PDFStamper to enable the PDF to stream
pdfStamper.Close();
}
catch (Exception)
{
SData.sLatestErr = Convert.ToString(Server.GetLastError());
Response.Redirect("Error.aspx", true);
}
finally
{
doc.Close();
Response.Redirect("~/test.pdf");
// TRY SAVING DATA
// To open in a new window
// METHOD 1
//Response.Write("<script>");
//Response.Write("window.open('~/test.pdf','_blank')");
//Response.Write("</script>");
//Response.Redirect("");
// METHOD 2
//Response.Write("<script type='text/javascript'>");
//Response.Write("window.open('test.pdf');");
//Response.Write("</script>");
// METHOD 3
//string url = "test.pdf";
//StringBuilder sb = new StringBuilder();
//sb.Append("<script type = 'text/javascript'>");
//sb.Append("window.open('");
//sb.Append(url);
//sb.Append("');");
//sb.Append("</script>");
//ClientScript.RegisterStartupScript(this.GetType(),"script", sb.ToString());
// METHOD 4
//Response.Write("<script type='text/javascript'>detailedresults=window.open('~/test.pdf');</script>");
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|