问题描述
我编写了一个代码来生成 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 报告...如何在新标签页或新页面中打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)