Я пришел к такому решению:
Создайте новую веб-форму ASP.NET (я назвал мою 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 передается на страницу через переменную Session с именем "fileLocation". Итак, все, что мне нужно, это установить эту переменную, а затем вызвать Response.Redirect("BinaryData.aspx")
.
Он не печатается автоматически, но запускает загрузку PDF, не покидая текущей страницы (что для меня достаточно).