我想将HTML + CSS页面转换为PDF文件。 我试过wkhtmltopdf,我遇到了问题,因为我想访问的网页需要在网站上进行身份验证。如何使用wkhtmltopdf将安全的HTML(ASP.NET MVC 3)页面转换为PDF?
页,我想转换为PDF格式有如下的URL:http:// [公司网址]/PDFReport/33
如果我尝试不认证来访问它,我重定向到登录页。
所以当我用wkhtmltopdf,它在我的登录页面转换为PDF ...
我在我的ASP.NET MVC应用程序中使用anthentication方法是SimpleMembership:
[Authorize]
public ActionResult PDFReport(string id)
{
}
我执行wkhtmltopdf .exe与System.Diagnostics.Process:
FileInfo tempFile = new FileInfo(Request.PhysicalApplicationPath + "\\bin\\test.pdf");
StringBuilder argument = new StringBuilder();
argument.Append(" --disable-smart-shrinking");
argument.Append(" --no-pdf-compression");
argument.Append(" " + "http://[WEBSITE]/PDFReport/33");
argument.Append(" " + tempFile.FullName);
// to call the exe to convert
using (Process p = new System.Diagnostics.Process())
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = Request.PhysicalApplicationPath + "\\bin\\wkhtmltopdf.exe";
p.StartInfo.Arguments = argument.ToString();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.WaitForExit();
}
您知道如何在不禁用此页面上的安全性的情况下生成PDF吗?
谢谢,我会尝试这种解决方法。 – Toc