生成水晶的报告PDF格式...如何在开放新标签或页面? [英] Generate Report of Crystal in PDF...How open in new tab or page?

查看:127
本文介绍了生成水晶的报告PDF格式...如何在开放新标签或页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个代码来生成水晶报表的PDF报告...但它在用户做了搜索,并在按钮按下的同一页面打开......有什么办法在新打开PDF ?选项卡或页面

I did a code to generate a report of Crystal Reports in PDF...But it opens in the same page of the user did a search and clicked in the button...Have any ways to open the PDF in a new tab or page ?

我的代码是:

private void OpenPDF()
{
    ReportDocument Rel = new ReportDocument();
    Rel.Load(Server.MapPath("../Reports/Test.rpt"));
    BinaryReader stream = new BinaryReader(Rel.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)));
    Response.Flush();
    Response.Close(); 
}



感谢您的帮助!

Thanks for the help!

推荐答案

在其最简单的解释,打开一个新窗口或标签,超链接的页面应该有目标属性设置为_空白

In its most simplest interpretation, to open a new window or tab, the hyperlink to the page should have the target attribute set to "_blank".

<a href="GeneratePDF.aspx" target="_blank">Link to open PDF in new window</a>



或者,你可以创建一些JavaScript,打开一个新的窗口,而不是。请确保你的地方调用JavaScript函数在页面上

Or you could create some Javascript that opens a new window instead. Make sure you call the Javascript function somewhere on the page.

<script type="text/javascript">
function loadPDF() {
   window.open('GeneratePDF.aspx','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
</script>



还是这个代码将告知浏览器该文件是一个下载(而非页面来查看在浏览器窗口内)。我觉得这是最好的办法,因为用户获得打开或保存PDF的选择。所以这不会做你问什么,但你可能会认为这是更好的。

Or this code will inform the web browser that the file is a download (rather than a page to view inside the browser window). I think this is the best approach because the user gets the choice of Opening or Saving the PDF. So this does not do what you're asking for, but you might think it's better.

private void OpenPDF(string downloadAsFilename)
{
    ReportDocument Rel = new ReportDocument();
    Rel.Load(Server.MapPath("../Reports/Test.rpt"));
    BinaryReader stream = new BinaryReader(Rel.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat));
    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment; filename=" + downloadAsFilename);
    Response.AddHeader("content-length", stream.BaseStream.Length.ToString());
    Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length)));
    Response.Flush();
    Response.Close(); 
}

这篇关于生成水晶的报告PDF格式...如何在开放新标签或页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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