NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

ArgumentException: progId not found. Word.Application #249

Closed jitutrivedi closed 5 years ago

jitutrivedi commented 5 years ago

Error Occurs When Published to web host ArgumentException: progId not found. Word.Application

I am try to Convert Docx to Pdf

` public ActionResult Paperview(string fname) {

        if (fname == string.Empty || fname == null)
        {

            ViewBag.msg = "File Creattion Fail";
            return View();
        }
        else
        {
            Word.Application wordApplication = new Word.Application();
            wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone;

            // create a utils instance, no need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(wordApplication);

            string path1 = Server.MapPath("~/Files/") + fname + ".docx";

            string path2 = Server.MapPath("~/Files/") + fname + ".pdf";

            Word.Document newDocument = wordApplication.Documents.Open(path1);

            newDocument.SaveAs2(path2, WdSaveFormat.wdFormatPDF);

            newDocument.Close(WdSaveOptions.wdDoNotSaveChanges);

            wordApplication.Quit(WdSaveOptions.wdDoNotSaveChanges);

            newDocument.Dispose();
            wordApplication.Dispose();

            ViewBag.msg = "File Creattion Success";
            return View();
        }

    }

`

jozefizso commented 5 years ago

Do you have Microsoft Word installed on your web server?

jitutrivedi commented 5 years ago

No not installed ! Please Help if possible .. I create word document using Openxml now try to convert Pdf using Netoffice

jozefizso commented 5 years ago

You must have Microsoft Word installed to work with Word.Application

jitutrivedi commented 5 years ago

any other solution to convert docx to Pdf without installation of Word.Application ?

jitutrivedi commented 5 years ago

`using NetOffice; using Word = NetOffice.WordApi; using NetOffice.WordApi.Enums;

using NetOffice.OfficeApi.Tools;

using EagleEyeWeb.Models;

` public ActionResult Paperview(string fname) {

        if (fname == string.Empty || fname == null)
        {

            ViewBag.msg = "File Creattion Fail";
            return View();
        }
        else
        {
            Word.Application wordApplication = new Word.Application();
            wordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone;

            // create a utils instance, no need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(wordApplication);

            string path1 = Server.MapPath("~/Files/") + fname + ".docx";

            string path2 = Server.MapPath("~/Files/") + fname + ".pdf";

            Word.Document newDocument = wordApplication.Documents.Open(path1);

            newDocument.SaveAs2(path2, WdSaveFormat.wdFormatPDF);

            newDocument.Close(WdSaveOptions.wdDoNotSaveChanges);

            wordApplication.Quit(WdSaveOptions.wdDoNotSaveChanges);

            newDocument.Dispose();
            wordApplication.Dispose();

            ViewBag.msg = "File Creattion Success";
            return View();
        }

    }