如何在iframe中显示从ftp服务器恢复的pdf或图像文件 [英] How to show pdf or image file retrived from ftp server in iframe
本文介绍了如何在iframe中显示从ftp服务器恢复的pdf或图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在IFrame控件中显示从FTP服务器检索到的pdf或图像文件
我尝试过:
string ParentFolder = ConfigurationManager.AppSettings [ DocReqFolder]。ToString();
int l = filePath.IndexOf(' 。')+ 1 ;
string Extn = filePath.Substring(l);
Ftp_FileHandler Ftp = new Ftp_FileHandler();
Ftp.FtpPath_withCredents();
Ftp.FTP_DownloadFile(filePath,ParentFolder);
var context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.AddHeader( Content-Disposition, attachment; filename = + filePath);
if (Extn.Contains( PDF )== true || Extn.Contains( pdf)== true )
HttpContext.Current.Response.ContentType = application / pdf;
else
HttpContext.Current.Response.ContentType = 应用/八位字节流跨度>;
context.Response.OutputStream.Write(Ftp.file, 0 ,Ftp.file.Length);
context.Response.End();
解决方案
将iframe的src属性设置为指向文档:
< iframe < span class =code-attribute> src = https://i.ytimg.com/ vi / 7rB0Hvt1i3Q / maxresdefault.jpg >
< p > 您的浏览器不支持iframe。< / p >
< / iframe >
如果您想直接流式传输内容而直接打印到文件,可以在这里看到:
使用简单网页流式传输文档 [ ^ ]
将Content-Disposition
设置为附件
强制浏览器下载文件。
将其更改为inline
让浏览器内联显示文件:
< pre lang =C#> context.Response.AddHeader( Content-Disposition, inline; filename = + filePath);
Content-Disposition - HTTP | MDN [ ^ ]
注意:有些浏览器不支持显示内联PDF。您需要使用像 PDF.js 这样的库[ ^ ]如果你需要支持它们。
I want to show pdf or image file retreived from FTP server in IFrame control
What I have tried:
string ParentFolder = ConfigurationManager.AppSettings["DocReqFolder"].ToString();
int l = filePath.IndexOf('.') + 1;
string Extn = filePath.Substring(l);
Ftp_FileHandler Ftp = new Ftp_FileHandler();
Ftp.FtpPath_withCredents();
Ftp.FTP_DownloadFile(filePath, ParentFolder);
var context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filePath);
if (Extn.Contains("PDF") == true || Extn.Contains("pdf") == true)
HttpContext.Current.Response.ContentType = "application/pdf";
else
HttpContext.Current.Response.ContentType = "application/octet-stream";
context.Response.OutputStream.Write(Ftp.file, 0, Ftp.file.Length);
context.Response.End();
解决方案
Set iframe's src attribute to point to the document:
<iframe src="https://i.ytimg.com/vi/7rB0Hvt1i3Q/maxresdefault.jpg"> <p>Your browser does not support iframes.</p> </iframe>
If you want to stream the content instead to pint to the file directly you can see here how:
Stream Your Documents Using Simple Web Page[^]
Setting theContent-Disposition
toattachment
forces the browser to download the file.
Change it toinline
to let the browser display the file inline:
context.Response.AddHeader("Content-Disposition", "inline; filename=" + filePath);
Content-Disposition - HTTP | MDN[^]
NB: Some browsers don't support displaying PDFs inline. You'll need to use a library like PDF.js[^] if you need to support them.
这篇关于如何在iframe中显示从ftp服务器恢复的pdf或图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文