我必须使用response.outputstream.write(bytes,0,filesize)在ifram中显示pdf; [英] I have to display pdf in ifram using response.outputstream.write(bytes, 0, filesize);

查看:141
本文介绍了我必须使用response.outputstream.write(bytes,0,filesize)在ifram中显示pdf;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以获得pdf浏览器,我希望它在iframe中使用通用处理程序







  byte  [] bytes =( byte  [])GetData(   SELECT * FROM [CME_Attachment]其中ID =' + ActID +  ')。行[ 0 ] [ 附件]; 

string name = name.pdf;
int FileSize = Convert.ToInt32(ddd.Rows [ 0 ] [ 4 ]的ToString());
Response.AddHeader( Content-type application / pdf);
Response.AddHeader( Content- Disposition attachment; filename = + name);
Response.OutputStream.Write(bytes, 0 ,FileSize);
Response.Flush();
Response.End();


iframepdf.Attributes [ src] =;





我的尝试:



 byte [] bytes =(byte [])GetData(SELECT [A_id],[Attachment],[A_name],[A_Ext],[A_size],[A_ActivityID],[ A_type]+ 
FROM [CME_Attachment]其中A_ActivityID ='+ ActID +'和A_type ='+ AttID +')。行[0] [附件];

string name = ddd.Rows [0] [2] .ToString();
int FileSize = Convert.ToInt32(ddd.Rows [0] [4] .ToString());
// int FileSize = Convert.ToInt32(row [A_size]。ToString());

Response.AddHeader(Content-type,application / pdf);
Response.AddHeader(Content- Disposition,attachment; filename =+ name);
Response.OutputStream.Write(bytes,0,FileSize);
Response.Flush();
Response.End();
iframepdf.Attributes [src]

解决方案

你不能发送包含iframe的html以及单个响应中的iframe内容,您需要将其拆分为两个请求。你需要你的原始页面来渲染一个iframe,其src元素指向一个只返回PDF的页面,即所有的Response。*行。您可能需要添加在查询字符串上生成文件所需的参数,以便您可以像现在一样阅读它们,但请注意,任何人都可以查看或修改这些参数,因此如果它们是敏感的,请不要这样做在本质上或如果你想让文件访问是短暂的。



返回pdf的页面不一定是处理程序,它可以是一个aspx页面(但是你需要在开始编写PDF之前添加一个response.clear),但没有理由不这样做,它会让你的生活变得更轻松,无论如何你必须为你的项目添加一个新文件。

I can get pdf to browser , i want it in iframe with out using generic handler



byte[] bytes = (byte[])GetData("SELECT   * FROM [CME_Attachment] where ID = '" + ActID + "'").Rows[0]["Attachment"];

              string name = name.pdf;
              int FileSize = Convert.ToInt32(ddd.Rows[0][4].ToString());
              Response.AddHeader("Content-type", "application/pdf");
              Response.AddHeader("Content-   Disposition", "attachment; filename=" + name);
              Response.OutputStream.Write(bytes, 0, FileSize);
              Response.Flush();
              Response.End();


              iframepdf.Attributes["src"] = ;



What I have tried:

byte[] bytes = (byte[])GetData("SELECT [A_id],[Attachment],[A_name],[A_Ext],[A_size] ,[A_ActivityID],[A_type]" +
              " FROM [CME_Attachment] where A_ActivityID = '" + ActID + "' and A_type = '" + AttID + "'").Rows[0]["Attachment"];

              string name = ddd.Rows[0][2].ToString();
              int FileSize = Convert.ToInt32(ddd.Rows[0][4].ToString());
              //int FileSize = Convert.ToInt32(row["A_size"].ToString());

              Response.AddHeader("Content-type", "application/pdf");
              Response.AddHeader("Content-   Disposition", "attachment; filename=" + name);
              Response.OutputStream.Write(bytes, 0, FileSize);
              Response.Flush();
              Response.End();
              iframepdf.Attributes["src"]

解决方案

You can't send html that contains an iframe and also the content of the iframe in a single response, you need to split this into two requests. You'll need your original page to render out an iframe whose src element points to a page that only returns the PDF, ie all of your Response.* lines. You'll probably need to add the params you need to generate the file on the querystring so you can read them as you're doing now, however note that anyone can view or modify those params so don't do that if they are sensitive in nature or if you want the file access to be short-lived.

The page that returns the pdf doesn't have to be a handler, it can be an aspx page (but you'll need to add a response.clear before you start to write the PDF) but there's no reason for it not to be, it makes your life easier and you have to add a new file to your project anyway.


这篇关于我必须使用response.outputstream.write(bytes,0,filesize)在ifram中显示pdf;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆