2010-05-25 61 views
1

我正在尝试将PDF文档放在网页中。但是,不要在网页中查看这个页面,当这个页面被调用时,问问我们是否想要保存/下载一个,然后在打开打印机对话框的情况下在Adobe中打开它。ASP.NET在网页上查看PDF

的Javascript其背后调用该页面加载功能

window.open("http://localhost:1843/PrintDocument.aspx?DocumentId="+id+"&Year="+year+"&Location="+loc); 

ASPX代码,页面加载功能:

protected void Page_Load(object sender, EventArgs e) 
     { 

      Response.ContentType = "Application/pdf"; 
      string yr = Request.QueryString["Year"].ToString(); 
      string Dyr = Convert.ToDateTime(yr).Year.ToString(); 
      string Location = Request.QueryString["Location"].ToString(); 
      string DocumentID = Request.QueryString["DocumentId"].ToString();  
      string PDFFile = string.Format(@"\\abc\def\pqr\{0}\{1}\{2}.pdf", Dyr, Location.Substring(0, 4), Location.Substring(4, 4)); 
      //Response.AddHeader("content-disposition", "attachment; filename=document.pdf"); 
      Response.WriteFile(PDFFile); 
      Response.End(); 
     } 
    } 

回答

1

我测试的Firefox此代码,它缺少的PDF插件。一旦我添加了这个插件 它开始使用我的代码。所以,当你在Firefox上使用PDF时,请确保你有PDF插件。

+1

或更好的是当有一个破损的PDF安装。 – ggonsalv 2010-05-28 02:08:11

1

有几种可能的版本。

例如你可以用最简单的方式,像

Response.Clear(); 

string filePath = ur file path on the server 

Response.contentType = "application/pdf"; 

Response.WriteFile(filePath); 

它已经讨论HERE。您也可以找到其他选项。 还要检查HEREHERE

您也可以使用自定义控制:PDF Control