在浏览器中加载PDF [英] Loading a PDF in browser
本文介绍了在浏览器中加载PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在asp.net中有一个按钮,称为下载PDf",因此当用户单击该按钮时,我希望将pdf加载到浏览器中.我对此一无所知.我确实没有对reasearch有所了解.谁能帮我这个忙,或者给我一些特定的链接,以便我可以去阅读它.
I have a button in asp.net called download the PDf so when a user click on that I want a pdf to be loaded in browser. I have no clue about that. I did reasearch still not having an idea. Can anyone help me that or give me some specific link so that I can go and read about it.
推荐答案
此MSDN文章
This MSDN article How To Write Binary Files to the Browser Using ASP.NET and Visual C# .NET[^] should help.
尝试一下:
Try this:
private void ReadPdfFile()
{
string path = @"C:\myfile.pdf";
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(path);
if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length",buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
希望对您有所帮助:)
hope it helps :)
这篇关于在浏览器中加载PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文