I Need to convert doc/docx to pdf with iTextSharp.dll.
I have converted different extensions to pdf format.
string[] fileType = hdnPath.Value.Split('.');
StreamReader str = new StreamReader(hdnPath.Value);
Document doc = new Document();
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();
In the above code .docx and xlsx format to pdf are not working