1
我在MVC ASP.NET C#中生成了一个HTML页面。 (与HTML佣工)ASP.NET MVC-将生成的HTML保存为PDF到文件夹
我想这个页面全自动保存为PDF中的特定文件夹
目前,当有人提出它获取发送到DB形式,但我也希望这样[HttpPost]把这一形式提交到PDF
例子:http://example1234.com/Persons/details/15
我如何将此保存为PDF?
private string datadir = null;
private string wkhtmltopdf = null;
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Person person)
{
datadir = ConfigurationManager.AppSettings["datadir"];
wkhtmltopdf = ConfigurationManager.AppSettings["wkhtmltopdf"];
if (ModelState.IsValid)
{
db.People.Add(person);
db.SaveChanges();
//here the PDF should be created
System.IO.File.WriteAllText("details/" + person.ID +".html"));
var pdf1 = new ProcessStartInfo(wkhtmltopdf);
pdf1.CreateNoWindow = true;
pdf1.UseShellExecute = false;
pdf1.WorkingDirectory = datadir + "tmp\\";
pdf1.Arguments = "-q -n --disable-smart-shrinking Pdf." + person.ID + ".html Pdf." + person.ID + ".pdf";
using (var process = Process.Start(pdf1))
{
process.WaitForExit(99999);
Debug.WriteLine(process.ExitCode);
}
return View(person);
}
你检查了http://stackoverflow.com/questions/779430/asp-net-mvc-how-to-get-view-to-generate-pdf? – Spock 2014-10-17 12:07:54