我正在使用下面的代码将pdf保存在我的MVC Razor中。
kendo.drawing.drawDOM($("#testDiv")).then(function(group)
{
group.options.set("pdf", {
margin: {
left: "10mm",
top: "20mm",
right: "10mm",
bottom: "20mm"
}
});
debugger;
kendo.drawing.pdf.saveAs(group, "save.pdf");
});
问题:是否可以将文件(pdf)保存在服务器中? 非常感谢任何帮助。
先谢谢。
答案 0 :(得分:1)
kendo.drawing.pdf.saveAs(group,"save.pdf");
会将文件推送到客户端的计算机上。
尝试这个,将其存储在服务器中。
void savetoServer()
{
StringBuilder stringBuilder = new StringBuilder();
StringWriter writer = new StringWriter(stringBuilder);
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
try {
testDiv.RenderControl(htmlWriter);
} catch (HttpException generatedExceptionName) {
}
var fileContents = stringBuilder.ToString();
var fileName = string.Format("drawing{0}.pdf", "[Your custom file name]");
string path = Path.Combine(Server.MapPath("~/Pdfs/"), Path.GetFileName(fileName));
//in above line "Pdfs" will map to the folder in your application root folder.
File.WriteAllBytes(path,fileContents);
}