【发布时间】:2018-07-06 00:15:48
【问题描述】:
早安,
我目前遇到 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 图像数组的工作,并且控制器似乎在完成它的工作,这是一个示例
渲染的 CSHTML:
我尝试按照我在此处找到的解决方案更新 rotativa 和 wkhtmltopdf,但没有运气获得预期的输出
希望有人能帮我解决这个问题..
非常感谢 Rotativa 和 ASP.net
感谢所有查看此内容的开发人员,我非常需要您的帮助:D
【问题讨论】:
标签: c# asp.net-mvc razor wkhtmltopdf