我目前正在使用MVC4中的RazorPDF组装和显示PDF,并希望在返回视图的同时将PDF文件保存到文件系统.
控制器操作中的以下代码行调用视图:
return new PdfResult(claims, "PDF");
Run Code Online (Sandbox Code Playgroud) 我需要使用Rotativa PDF在页眉或页脚上插入一些图像.
我正在使用带有Razor的C#MVC4
我已经尝试过:CustomSwitches =" - print-media-type --header-center \"text \""
我正在使用RazorPDF,我想强制下载PDF而不是在浏览器选项卡中打开.我该怎么做呢?谢谢
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string Id)
{
return RedirectToAction("Pdf");
}
public PdfResult Pdf()
{
// With no Model and default view name. Pdf is always the default view name
return new PdfResult();
}
Run Code Online (Sandbox Code Playgroud) 看到这个链接将html转换为pdf我在webconfig中得到了这个版本错误让一些天才找到并解决了qustion.
我的模特
public class Customer
{
public int CustomerID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的控制器这是正常的代码
public ActionResult Index()
{
List<Customer> customers = new List<Customer>();
for (int i = 1; i <= 10; i++)
{
Customer customer = new Customer
{
CustomerID = i,
FirstName = string.Format("FirstName{0}", i.ToString()),
LastName = string.Format("LastName{0}", i.ToString())
};
customers.Add(customer);
}
return View(customers);
}
Run Code Online (Sandbox Code Playgroud)
这是为pdf转换控制器
public ActionResult PDF()
{
List<Customer> customers = …Run Code Online (Sandbox Code Playgroud) 我正在使用mvc4,这里我razorpdf用来将我的视图转换为pdf,但是我收到了一个错误 - Unable to cast object of type iTextSharp.text.Paragraph to type iTextSharp.text.Table.
这是我正在使用的示例代码:
@{
Layout = "~/Views/Shared/_PdfLayout.cshtml";
}
<html>
<body>
<table border="1" width='500' bordercolor="RED"><tr><td colspan="3" bgcolor="LightGreen" align="center" valign="top">SSLC Marks Sheet 2013</td></tr></table></body>
</html>
Run Code Online (Sandbox Code Playgroud)