如何打开Pdf文件 [英] How Do I Open The Pdf File

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

问题描述

您好

我想在浏览器中打开pdf文件,该文件存储在服务器端文件夹中。

如何在.net中映射该路径以及如何操作它在asp.net中使用c#进行编码,为我提供了教程。





 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Net;
使用 System.IO;


public partial class open_pdf:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{

}
protected void btn_open_Click( object sender,EventArgs e)
{
string open_path = Server.MapPath( 〜/上传/ IPM.pdf);
WebClient client = new WebClient();
字节 [] buffer = client.DownloadData(open_path);
Response.ContentType = application / pdf;
Response.AddHeader( content-length,buffer.Length.ToString()) ;
Response.BinaryWrite(buffer);
Response.Flush();
Response.End();
}
}









< pre lang =xml> <%@ 页面 语言 = < span class =code-keyword> C# AutoEventWireup = true CodeFile = open_pdf.aspx.cs 继承 = open_pdf %>

< !DOCTYPE html >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = 服务器 >
< title > < / title >
< / head >
< body >
< 表格 id = form1 runat = 服务器 >
< div >

< asp:按钮 ID < span class =code-keyword> = btn_open runat = server OnClick = btn_open_Click 文字 = open pdf / >

< / div >
< / form >
< / body >
< / html >





打开pdf但在现有标签中没有新标签或新窗口

解决方案

查看此链接



http://forums.asp.net/post/2173534.aspx [ ^ ]


您可以参考此链接



http://social.msdn.microsoft.com/Forums/vstudio/en-US/3299861c-e58d-42ae-a5d0-b66ef84db704/opening-pdf-programmatically [ ^ ]


Hello
I want to open the pdf file in the browser which is stored in server side folder.
how to map that path in .net and how to do its coding in asp.net with c# provide me tutorial.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;


public partial class open_pdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_open_Click(object sender, EventArgs e)
    {
        string open_path = Server.MapPath("~/upload/IPM.pdf");
        WebClient client = new WebClient();
        Byte[] buffer = client.DownloadData(open_path);
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);
        Response.Flush();
        Response.End();
    }
}





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="open_pdf.aspx.cs" Inherits="open_pdf" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Button ID="btn_open" runat="server" OnClick="btn_open_Click" Text="open pdf" />

    </div>
    </form>
</body>
</html>



That open the pdf but in exist tab not new tab or new window

解决方案

check this link

http://forums.asp.net/post/2173534.aspx[^]


You can refer this link

http://social.msdn.microsoft.com/Forums/vstudio/en-US/3299861c-e58d-42ae-a5d0-b66ef84db704/opening-pdf-programmatically[^]


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

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