打开pdf而不用“打开方式”和“保存”单选按钮询问窗口 [英] open pdf without asking the window with 'Open with' and 'save' radio buttons

查看:113
本文介绍了打开pdf而不用“打开方式”和“保存”单选按钮询问窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,



我正在将gridview中的所有内容写成PDF格式。



它是使用打开方式和保存选项生成一个窗口。



这里我的要求是如何在没有此窗口的情况下打开PDF。

这意味着在弹出窗口中打开事件想要在后台工作..



请帮帮我。

提前致谢。



我在下面给出的代码..

此代码与打开的窗口完美配合..





protected void imgPdf_Click(object sender,EventArgs e)

{

using(StringWriter sw = new StringWriter())

{

使用(HtmlTextWriter hw = new HtmlTextWriter(sw))

{

try

{

//导出所有页面

grdRequestList.AllowPaging = false;

BindGrid();



grdRequestList.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());

文档pdfDoc =新文档(PageSize.A2,10f,10f,10f,0f);

HTMLWorker htmlparser =新的HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc,Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse (sr);

pdfDoc.Close();



Response.ContentType =application / pdf;

Response.AddHeader(content-disposition,attachment; filename = GridViewExport.pdf);

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Write(pdfDoc);

HttpContext.Current.ApplicationInstance.CompleteRequest();

// PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);

//Response.End();

}

catch(例外情况)

{



抛出Ex;

}

}

}

}

Sir,

I am writing all contents inside a gridview to PDF.

It is generating a window with 'Open with' and 'Save' option.

Here my requirement is how to open that PDF without this window.
That means the open with event in popup window want to work in background..

Please help me.
Thanks in advance.

My code i am giving below..
This code is working perfectly with the open with window..


protected void imgPdf_Click(object sender, EventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
try
{
//To Export all pages
grdRequestList.AllowPaging = false;
BindGrid();

grdRequestList.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
HttpContext.Current.ApplicationInstance.CompleteRequest();
//PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
//Response.End();
}
catch (Exception Ex)
{

throw Ex;
}
}
}
}

推荐答案

它不在您手中。浏览器如何处理下载的内容很复杂...

mime类型 - 它是否为浏览器所知?有一个应用程序分配给它?

用户的偏好 - 用户希望如何处理特定内容?



你可能想出一个解决方案(主要使用iframe)可以在大多数IE浏览器上运行,但不能在其他任何地方使用,也不适用于自定义IE ...

所以不要浪费你的时间...
It's not in your hand. How browsers handle downloaded content is complicated by several thing...
The mime type - does it known for the browser? There is an application assigned to it?
The user's preferences - how user wish to handle specific content?

You may come up with a solution (mostly using iframe) that will work on most IE browsers, but not anywhere else and not on customized IE too...
So do not waste your time...


这篇关于打开pdf而不用“打开方式”和“保存”单选按钮询问窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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