2011-10-14 108 views
-1

这是处理程序代码:如果我直接导​​航到此处理程序,它显示PDF罚款。在Aspx页面上我有一个图像控件,pdf不会在imagecontrol中显示。 Accroding所有的谷歌搜索这应该在图像控件中显示aspx页面上使用ashx(处理程序)文件打开pdf

public void ProcessRequest(HttpContext context) 
    { 

      WebClient imageWebClient = new WebClient(); 
      byte[] imageBytes = imageWebClient.DownloadData(Testlocation); 
      context.Response.ClearHeaders(); 
      //context.Response.ClearContent(); 
      context.Response.AddHeader("content-disposition", "inline; filename=image.pdf"); 
      context.Response.ContentType = "application/pdf"; 
      context.Response.AddHeader("Content-Length", imageBytes.Length.ToString()); 
      context.Response.BinaryWrite(imageBytes); 
      context.Response.Flush(); 

}

标记:

+1

您正在讨论图像控制 - 我无法在文档中看到任何指定它可以显示pdf的地方 –

回答

3

Accroding所有谷歌搜索这应该在图像控制中显示

不知道你所指的是什么搜索,但图像控件应该显示图像,而不是PDF。图像控件在HTML中呈现为<img>标签。 <img>标签只能与图像一起使用。如果您想在页面中嵌入PDF,您可以使用将其src属性指向您的ashx处理程序。

+0

我已经完成了这项工作,它在Iframe中显示正常。 – user228777

+0

@ user228777,有什么你想问的吗? –