我到达的解决方案是这样的:
创建一个新的ASP.NET Web窗体(我叫雷为BinaryData.aspx)作为对PDF的占位符。在后面的代码,唯一的方法应该是Page_Load中,它看起来像:
protected void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Cache-Control", "no-cache");
//Get the physical path to the file.
string FilePath = (string)Session["fileLocation"];
if (FilePath != null)
{
string FileName = Path.GetFileName(FilePath);
Response.AppendHeader("Content-Disposition", "attachment; filename="+FileName);
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
}
的PDF在页面通过名为“fileLocation”会话变量传递。所以,我必须设置该变量,然后致电Response.Redirect("BinaryData.aspx")
。
它不会自动打印,但会触发下载PDF而不离开当前页面(这对我来说已经足够了)。
这听起来像它将会在更加复杂的方向 - 它当然可以工作,但我宁愿保持独立的PDF网页的行为。 – 2009-08-03 17:33:40