0

I am trying to convert html string from my view to image. I am able to get my view as string but not able to convert it in image(base64string or byte array) to return it back. This is my code

/* Getting label design info */
LabelDesigner ObjModel = GetLabelDesignObject("Drug_Label");

/* Taking view's HTML */
string HTML = RenderRazorViewToString("~/Views/Folder/DrugLabel.cshtml", ObjModel);

.............
.............
.............
.............

public string RenderRazorViewToString(string ViewName, object Model)
    {
        string ReturnVal = string.Empty;

        try
        {
            ViewData.Model = Model;
            using (var sw = new System.IO.StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, ViewName);
                var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();
            }
        }
        catch (Exception ex)
        {
            /* Catch Exception Here */
            log.Error("Error in Controller.cs, RenderRazorViewToString function: " + ex.Message);
        }

        return ReturnVal;
    }

Here I am able to get HTML of view but how to convert that HTML string to jpg image?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.