【发布时间】:2013-05-07 06:47:43
【问题描述】:
我目前正在使用带有 c# 的 wkhtmltopdf 将我的网页下载为 PDF 格式。但是,我希望生成的 PDF 显示为使用“print.css”。
其他细节: 我正在使用 Microsoft Visual Studio 2010。
这是我的代码:
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
string args = string.Format("\"{0}\" - ", Request.Url.AbsoluteUri);
var startInfo = new ProcessStartInfo(Server.MapPath("~/wkhtmltoPDF/") + "wkhtmltopdf.exe", args)
{
UseShellExecute = false,
RedirectStandardOutput = true
};
var proc = new Process { StartInfo = startInfo };
proc.Start();
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=StaffDetails.pdf", Guid.NewGuid()));
Response.AddHeader("Content-Type", "application/pdf"); string output = proc.StandardOutput.ReadToEnd();
byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output);
proc.Close();
Response.BinaryWrite(buffer);
}
}
【问题讨论】:
标签: c# asp.net pdf-generation wkhtmltopdf