User381809404 posted
Hi,
I am success to create pdf file by using iTextSharp. but now i have to open automatically. and its not working.
here is my code.
private void GeneratePDF(string path, string fileName)
{
var doc = new Document();
try
{
PdfWriter.GetInstance(doc, new FileStream(path + fileName, FileMode.Create)); doc.Open();
for (int i = 0; i < L.Count; i++)
{
doc.NewPage();
using (TextReader sReader = new StringReader(L[i].ToString()))
{
List<IElement> list = HTMLWorker.ParseToList(sReader, new StyleSheet());
foreach (IElement elm in list) { doc.Add(elm); }
}
}
}
catch (Exception ex) { ex.Message.ToString(); }
finally
{
doc.Close();
OpenPDF(doc);
}
}
private void OpenPDF(Document doc)
{
Response.AddHeader("Content-Disposition", "attachment;filename=test.pdf");
Response.ContentType = "application/pdf";
Response.End();
}
i am getting Error: "Adobe Reader could not open because it is either not a supported file type or because the file has been damaged."
please help