在浏览器中从数据库打开PDF [英] Open PDF in browser from database

查看:131
本文介绍了在浏览器中从数据库打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我的PDF字节存储在数据库中.我的ASP.Net网站上有一个通用文件处理程序(ashx).我当前的代码有效,但是下载了PDF.我如何打开一个新窗口并显示它.这是我当前的代码:

Hi have the bytes of my PDF stored in my database. I have a generic file handler(ashx) in my ASP.Net website. My current code works, but downloads the PDF. How can I open a new window and display it. Here is my current code:

using (DataContext fdData = new DataContext())
            {
                 GetFormData_Result result = fdData.GetFormData(fileId).First();

                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=\"" + result.Name + ".pdf\"");
                HttpContext.Current.Response.ContentType = "application/pdf";

                if (HttpContext.Current.Response.IsClientConnected)
                    HttpContext.Current.Response.BinaryWrite(result.pdfbackground);
            } 



预先感谢.



Thanks in advance.

推荐答案

删除"content-disposition"标头,并且pdf将在浏览器中打开(如果客户端已安装阅读器).
如果要在新窗口中打开它,请使用javaScript window.open方法,并将URL传递给您的处理程序.
Remove "content-disposition" header and pdf will open in browser (if client has reader installed).
If you want it to open in new window use javaScript window.open method and pass it the URL to your handler.


HI,
如果您浏览该文件,它将在浏览器中打开
HI ,
IF you naviage to the File it will open in browser
Response.Redirect("~/File.pdf");


最好的问候
米特瓦里(M.Mitwalli)


Best Regard
M.Mitwalli


这篇关于在浏览器中从数据库打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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