string[] fileType = hdnPath.Value.Split('.'); StreamReader str = new StreamReader(hdnPath.Value); Document doc = new Document(); // Element ea = new Element(); if (fileType[fileType.Length - 1] == "txt") { PdfWriter.GetInstance(doc, new FileStream(hdnPath.Value.Replace(".txt", ".pdf"), FileMode.Create)); } else if (fileType[fileType.Length - 1] == "docx") { PdfWriter.GetInstance(doc, new FileStream(hdnPath.Value.Replace(".docx", ".pdf"), FileMode.Create)); } else if (fileType[fileType.Length - 1] == "aspx") { PdfWriter.GetInstance(doc, new FileStream(hdnPath.Value.Replace(".aspx", ".pdf"), FileMode.Create)); } else if (fileType[fileType.Length - 1] == "cs") { PdfWriter.GetInstance(doc, new FileStream(hdnPath.Value.Replace(".cs", ".pdf"), FileMode.Create)); } else if (fileType[fileType.Length - 1] == "xlsx") { PdfWriter.GetInstance(doc, new FileStream(hdnPath.Value.Replace(".xlsx", ".pdf"), FileMode.Create)); } else if (fileType[fileType.Length - 1] == "xlsx") { lblErrorMessage.Text = "Not required to convert pdf to pdf format"; } else { lblErrorMessage.Text = "We can't convert this file"; } doc.Open(); doc.Add(new Paragraph(str.ReadToEnd())); doc.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)