如何在网页本身中打开pdf文件 [英] How to open pdf file in webpage itself

查看:159
本文介绍了如何在网页本身中打开pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要在网页本身中打开一个pdf文件,而不要求我保存/取消/打开.

我已经编码了如何使用保存选项和在网页外部打开pdf文件.我正在发布该代码供您参考.

hi all,

i need to open a pdf file within web page itself without ask me to save/cancel/open.

i have coding for how to open pdf file with the save options and outside of web page . i am posting for that code for your reference.

path="" need to mention here.
       System.Net.WebClient client = new System.Net.WebClient();
       Byte[] buffer = client.DownloadData(path);

       if (buffer != null)
       {
           Response.ContentType = "application/pdf";
           Response.AddHeader("content-length", buffer.Length.ToString());
           Response.BinaryWrite(buffer);
       }


我只需要打开网页本身而不打开或保存即可.


i need just open inside the web page itself without saking open or save.

推荐答案

在Response.ContentType之后添加此行.
Add this line after Response.ContentType.
Response.AppendHeader("content-disposition", "inline; filename=sample.pdf");


或仅提供pdf的URL路径,如下所示.


or just give the URL path of the pdf like below.

Response.Redirect("www.sample.com/folder/test.pdf"); //In your case path


请尝试以下代码.

Try as below code.

string path = Server.MapPath("PDFFileFolder") + @"\MyPDFFile.pdf";
System.Net.WebClient client = new System.Net.WebClient();
Byte[] buffer = client.DownloadData(path);

 if (buffer != null)
 {
   Response.ContentType = "application/pdf";
   Response.AddHeader("content-length", buffer.Length.ToString());
   Response.BinaryWrite(buffer);
 }



试试这个

Hi
try this one

Response.Redirect("~/Yourfolder/file.pdf"); 




谢谢.




Thanks.


这篇关于如何在网页本身中打开pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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