从asp.net打开pdf文件 [英] Open pdf file from asp.net
本文介绍了从asp.net打开pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Response.ContentType =Application / whoispp-response
Response.AddHeader(Content-disposition,inline; filename = Reportname.pdf)
Response.BinaryWrite(bytes)
Response.Flush()
它是在没有要求打开对话框的情况下在acrobat中打开pdf,
但是出现了一个问题,即查看器页面显示为空,我想显示另一个页面,怎么可能?
解决方案
尝试Response.TransmitFile()
从ASP.NET应用程序中显式发送文件。这将导致打开/另存为对话框弹出文件名。
访问此 [在ASP.NET中使用另存为对话框下载文件]获取更多信息。
你试过window.open()方法...
如果你想在新标签页面中点击超链接打开pdf文件,请按以下步骤操作/>
1:添加一个表格作为PDFViewer.aspx。
2:在此表格的Page_Load事件中添加以下代码。
受保护 void Page_Load(对象发件人,EventArgs e)
{
如果(!IsPostBack)
{
Response.ClearHeaders();
Response.ClearContent();
Response.Redirect( nameofPDFFile.pdf);
}
}
3.设置超链接的属性如下:
< asp:HyperLink ID = HyperLink1 runat = server NavigateUrl = 〜/ PDFViewer.aspx
目标 = _ blank > HyperLink < / asp:HyperLink >
Response.ContentType = "Application/whoispp-response" Response.AddHeader("Content-disposition", "inline;filename=Reportname.pdf") Response.BinaryWrite(bytes) Response.Flush()
It is open pdf in acrobat without asking open dialog box,
but one problem arise ,that is the viewer page is shown as empty , I want to show another page , how it is possible?
解决方案
TryResponse.TransmitFile()
to explicitly send the file from your ASP.NET application. This will cause a Open / Save As dialog box to pop up with the filename.
Visit this [Downloading a File with a Save As Dialog in ASP.NET] for more info.
did you tried window.open() method...
If you want to open pdf File in new Tab with clicking hyperlink follow this
1: Add one form as PDFViewer.aspx.
2: on the Page_Load event of this form add following code.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Response.ClearHeaders(); Response.ClearContent(); Response.Redirect("nameofPDFFile.pdf"); } }
3. set properties of hyperlink is follows:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/PDFViewer.aspx" Target="_blank">HyperLink</asp:HyperLink>
这篇关于从asp.net打开pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文