我使用wkhtmltopdf
到HTML文件转换成PDF文档的链接按钮 http://code.google.com/p/wkhtmltopdf/与wkhtmltopdf.exe路径问题HTML文件转换成PDF
当如用户点击运行下面的代码链接按钮在传递文件路径下面的代码作为参数ProcessStartInfo。此代码工作正常在下列情况下,只有
考虑到网站上域http://www.xyz.net/
- 托管当我提到路径
http://demo.XYZ.net/
它工作正常 - 当我提到路径
http://www.XYZ.net/
它不工作 - 套内本地主机的正常工作,如果路径是
http://localhost:51005/XYZ/
或http://web:8080/
为了这个正常工作,我们需要给网站的完全信任级别&我不知道为什么代码不运行,我给它同样的域路径,如果我创建如果我创建一个子域,然后它将正常工作PrintArticle.aspx
。我NOST知道这是一个安全问题,或者什么
下面的代码
protected void lnkbtnDownload_Click(object sender, EventArgs e)
{
//ConvertURLToPDF();
try
{
string url = "PrintArticle.aspx?articleID=" + Request["articleID"] + "&download=yes&Language=" + Request["Language"];
//string args = string.Format("\"{0}\" - ", "http://demo.XYZ.net/" + url); //Works
//string args = string.Format("\"{0}\" - ", "http://www.xyz.net/" + url); Doesnt work
//string args = string.Format("\"{0}\" - ", url);
string args = string.Format("\"{0}\" - ", "http://localhost:51005/XYZ/" + url); //Works
var startInfo = new ProcessStartInfo(Server.MapPath("bin\\wkhtmltopdf.exe"), args)
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
};
var proc = new Process { StartInfo = startInfo };
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output);
proc.WaitForExit();
proc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=download.pdf");
Response.BinaryWrite(buffer);
Response.End();
}
catch (Exception ex)
{
throw ex;
}
}
错误消息的情况下,文件是在同一个域中
服务器错误“/”应用。无法找到该资源。
描述:HTTP 404.您正在查找的资源(或其中一个 依赖项)可能已被删除,名称已更改,或者 暂时不可用。请查看以下网址并确保 拼写正确。 请求的网址:/PrintArticle.aspx
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272