How do i convert a jpg/png/txt or any file format to pdf using mvc c#. Here is the code:
- public ActionResult SaveProfileDocument(string code)
- {
- bool isSavedSuccessfully = true;
- string fName = "";
- string _documentname = String.Empty;
- try
- {
- foreach (string fileName in Request.Files)
- {
- HttpPostedFileBase file = Request.Files[fileName];
- //Save file content goes here
- fName = file.FileName;
- if (file != null && file.ContentLength > 0)
- {
- var originalDirectory = new DirectoryInfo(string.Format("{0}Documents\\Profile\\" + code, Server.MapPath(@"\")));
- string pathString = System.IO.Path.Combine(originalDirectory.ToString());
- var fileName1 = Path.GetFileName(file.FileName);
- bool isExists = System.IO.Directory.Exists(pathString);
- if (!isExists)
- System.IO.Directory.CreateDirectory(pathString);
- _documentname=fName;
- var path = string.Format("{0}\\{1}", pathString, file.FileName);
- if (System.IO.File.Exists(path)) {
- _documentname=Guid.NewGuid()+"_"+file.FileName;
- var path2 = string.Format("{0}\\{1}", pathString,_documentname );
- file.SaveAs(path2);
- }
- else {
- file.SaveAs(path);
- }
- }
- }
- }
- catch (Exception ex)
- {
- isSavedSuccessfully = false;
- }
- if (isSavedSuccessfully)
- {
- return Json(new { Message = fName, documentname = _documentname });
- }
- else
- {
- return Json(new { Message = "Error in saving file", documentname=""});
- }
- }
In the above code i am saving the file.but here i need to convert the file and then save.
so for convert i need a separate class or method here only call that method.
The thing is that while upload a file inthat time need to convert pdf any file to convert pdf. and save in folder or whatever.

alice yangRank #2,329 · 607 reputationPosted Apr 25, 2017, 8:22 PM EDT
Khaja MoizuddinRank #270 · 9.4K reputationPosted Apr 25, 2017, 8:56 AM EDT
Manoj MaharanaRank #4,500 · 340 reputationPosted Apr 25, 2017, 8:18 PM EDT
Sameer ShaikRank #1,825 · 812 reputationPosted Apr 25, 2017, 9:08 PM EDT
Manoj MaharanaRank #4,500 · 340 reputationPosted Apr 26, 2017, 1:02 AM EDT
Mohamed AbedallahRank #2,074 · 697 reputationPosted Apr 26, 2017, 8:09 AM EDT
https://www.leadtools.com/help/leadtools/v19m/dh/doxc/documentconverter.html