I have read and tried a lot of solutions on how to convert an HTML file to a word document. (ex: http://www.sautinsoft.com/products/pdf-focus/convert_pdf_to_word_rtf_text_asp_net.php )

But, up to this day, I'm still unlucky to get the perfect solution.

I have an HTML that I render as a string and then convert to PDF using the wkhtmltopdf.exe

myView = RenderPartialViewToString("~/Views/Shared/myHTML.cshtml", model);
protected string RenderPartialViewToString(string viewName, object model)
        if (string.IsNullOrEmpty(viewName))
            viewName = ControllerContext.RouteData.GetRequiredString("action");

        ViewData.Model = model;

        using (StringWriter sw = new StringWriter())
            ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
            ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
            viewResult.View.Render(viewContext, sw);
            return sw.GetStringBuilder().ToString();

But this time, I want to have a word document version of it as well.

Related posts

Recent Viewed