public jsonResult Convertfiletopdf(string filename , string filePatgh) { try { filePatgh = Path.Combine(Server.MapPath("~/Uploads/")); if (filename.Contains(".xlsx")) { var newfilename = filename.Replace(".xlsx", ".pdf"); var app = new Application(); var wkb = app.Workbooks.Open(filePatgh + filename); if (!System.IO.File.Exists(filePatgh + newfilename)) { wkb.ExportAsFixedFormat( XlFixedFormatType.xlTypePDF, filePatgh + newfilename, XlFixedFormatQuality.xlQualityStandard, true, true, 1, 10, false); } wkb.Close(); } if (filename.Contains(".xls")) { var newfilename = filename.Replace(".xls", ".pdf"); var app = new Application(); var wkb = app.Workbooks.Open(filePatgh + filename); if (!System.IO.File.Exists(filePatgh + newfilename)) { wkb.ExportAsFixedFormat( XlFixedFormatType.xlTypePDF, filePatgh + newfilename, XlFixedFormatQuality.xlQualityStandard, true, true, 1, 10, false); // wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, filePatgh + newfilename); } wkb.Close(); } else { var objWorPdf = new Word2Pdf(); var fromLocation = filePatgh + "\\" + filename; var fileExtension = Path.GetExtension(filename); var changeExtension = filename.Replace(fileExtension, ".pdf"); object toLocation = filePatgh + "\\" + changeExtension; objWorPdf.InputLocation = fromLocation; objWorPdf.OutputLocation = toLocation; if (!System.IO.File.Exists(filePatgh + changeExtension)) { objWorPdf.Word2PdfCOnversion(); } } return Json(filename, JsonRequestBehavior.AllowGet); } catch (Exception ex) { throw ; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)