good morning all, I found sample code to let me save current page to a pdf using itextsharp library and then save it to a temp folder within the site automatically. But the one thing that it kept doing was that it kept triggering the browser to prompt me to download or save the file. The file is already save in a temp folder, I just want to disable that browser dialog download somehow. please advise. Any help is really appreciated. thank you
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=RequestSummaryReport.pdf");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/pdf";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(PageSize.A3, 45, 5, 5, 5);
//PdfWriter writer = PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
PdfWriter writer = PdfWriter.GetInstance(pdfDocument, new FileStream(Server.MapPath("~/temps/") + "mypdf.pdf", FileMode.CreateNew));
pdfDocument.Open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(pdfDocument, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser xmlParse = new XMLParser(true, worker);
this.Page.RenderControl(htw);
StringReader sr = new StringReader(sw.ToString());
xmlParse.Parse(sr);
xmlParse.Flush();
pdfDocument.Close();
//Response.Write(pdfDocument);
Response.End();