Rotativa WKHTMLTOPDF呈现基础64图像

时间:2018-07-06 00:15:48

标签: c# asp.net-mvc razor wkhtmltopdf

美好的一天,

我目前正在遇到Rotativa。ViewAdPdf不在ASP.net中呈现动态base64图像。.CSS正在处理设计,而rotativa正在呈现它。谁能帮我?请..先谢谢

这是我的代码:

CSHTML:

 <div Id="mainImageContainer">
                                    @if (Model.Question.MainQuestionImage != null)
                                    {
                                        <img alt="Main Image" src="@String.Format("data:{0};base64,{1}", Model.Question.MainQuestionImage.contentType, Model.Question.MainQuestionImage.content64base)" />

                                    }

                                </div>

控制器:

   public ActionResult RenderReportData(int schedId, int userId)
        {
            ScheduleExaminerModel model = new ScheduleExaminerModel();
            model = BaseMethods.GetDetails(x => x.ScheduleId == schedId && x.UserId == userId);

            ScheduleExaminerViewModel viewModel = new ScheduleExaminerViewModel();
            List<questionCorrectionViewModel> listQuestion = new List<questionCorrectionViewModel>();
            if (model != null)
            {
                viewModel.Id = model.Id;
                viewModel.User = model.User;
                viewModel.Schedule = model.Schedule;

                foreach (var item in model.Questions)
                {
                    questionCorrectionViewModel currenQuestionModel = new questionCorrectionViewModel();
                    bool iscorrect = checkAns(item);

                    currenQuestionModel.Question = item.Question;
                    currenQuestionModel.UserAnswer = item.UserAnswer;
                    currenQuestionModel.IsCorrect = iscorrect;

                    if (item.Question.QuestionType == "Essay")
                    {
                        currenQuestionModel.essayStatus = checkAnswerEssay(item);
                    }
                    listQuestion.Add(currenQuestionModel);
                }
                viewModel.CorrectedQuestion = listQuestion;



                Dictionary<string, string> cookieCollection = new Dictionary<string, string>();
                foreach (var key in Request.Cookies.AllKeys)
                {
                    cookieCollection.Add(key, Request.Cookies.Get(key).Value);
                }
                string footer = "--footer-right \"Date: [date] [time]\" " + "--footer-center \"Page: [page] of [toPage]\" --footer-line --footer-font-size \"9\" --footer-spacing 5 --footer-font-name \"calibri light\"";




                return new ViewAsPdf("UserExaminationReport", viewModel)
                {
                    Cookies = cookieCollection,
                    PageSize = Size.Letter,
                    CustomSwitches = footer
                };



            }
            else
            {
                return RedirectToAction("SystemMessage", new { message = "Record Not found" });
            }

        }

型号:

 public class FileRepositoryItem : IDataChangeTracker
    {
        public int Id { get; set; }

        public byte[] byteContent { get; set; }
        public string contentType { get; set; }
        public decimal contentLenght { get; set; }


        public DateTime DateCreated { get; set; }
        public DateTime LastDateUpdated { get; set; }
        public string CreateUser { get; set; }
        public string LastUpdateUser { get; set; }
        public bool IsDeleted { get; set; }

        [NotMapped]
        public string content64base
        {
            get
            {
                return Convert.ToBase64String(byteContent,0,byteContent.Length);
            }
        }
    }

我已经检查CSHTML是否正在执行其工作,以从控制器返回base64图像数组,并且contoller似乎在做一个工作

RENDERED CSHTML:

enter image description here

ive尝试根据此处找到的解决方案ive更新rotativa和wkhtmltopdf,但没有运气获得期望的输出

enter link description here

希望有人可以帮助我。

感谢Rotativa和ASP.net

请注意查看此信息的所有开发人员,我非常需要您的帮助:D

1 个答案:

答案 0 :(得分:0)

已经解决了这个问题,我只需要卸载Rotativa即可获取nuget并手动删除连接二进制文件的所有文件。并重新安装更新的轮状面包