以 PDF 格式生成 Crystal 报告...如何在新标签页或新页面中打开?

Generate Report of Crystal in PDF...How open in new tab or page?(以 PDF 格式生成 Crystal 报告...如何在新标签页或新页面中打开?)
本文介绍了以 PDF 格式生成 Crystal 报告...如何在新标签页或新页面中打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个代码来生成 PDF 格式的 Crystal Reports 报告...但它在用户搜索并单击按钮的同一页面中打开...有任何方法可以在新页面中打开 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(); 
}

感谢您的帮助!

推荐答案

在最简单的解释中,要打开一个新窗口或选项卡,页面的超链接应该将 target 属性设置为_blank".

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 格式生成 Crystal 报告...如何在新标签页或新页面中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)