在水晶报表中以编程方式设置页边距 [英] set page margins programmatically in crystal report

查看:556
本文介绍了在水晶报表中以编程方式设置页边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用水晶报告为我的一个报告。我需要为报告动态设置边距。边距由用户设置,所以我需要以编程方式应用边距。

I m using crystal report for one of my report. I need to set the margins dynamically for the report. The margins are being set by user so I need to apply the margins programmatically.

我使用以下代码以编程方式设置边距。

I am using the below code to set the margins programmatically.

ReportDocument rd = new ReportDocument();
PageMargins pageMargins = new PageMargins();
pageMargins.leftMargin = 25;
pageMargins.topMargin = 100;
pageMargins.rightMargin = 25;
pageMargins.bottomMargin = 50;
rd.PrintOptions.ApplyPageMargins(pageMargins);

,然后向用户显示打印预览,然后用户可以打印。我使用下面的代码显示预览。

and then show preview of print to the user and then user can print. I am using below code for showing preview.

Response.Buffer = false;
Response.ClearHeaders();
Response.ClearContent();
rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "Print");

以上不适用于我。它不应用边距(当我从设计 - >页面设置中静态设置边距时同样适用)。它显示内容,就像在动态使用边框时不应用边距。我已附加图片显示为预览。

Above is not working for me. It doesn't apply margins (The same is working when I set margins statically from Design -> Page Setup). It shows the content as if margins are not applied when used dynamically. I have attached the image for how it is being shown as preview.

任何人都可以帮助我的问题是什么?为什么不应用边距?

Can anybody help me for what can be the problem? Why margins are not being applied?

推荐答案

我找到了这个问题的解决方案。我之前使用的代码只有一点变化。我使用下面的代码。

I found the solution for this problem. There is only a little change with the code I used earlier. I used the code below.

ReportDocument rd = new ReportDocument();
PageMargins margins;
// Get the PageMargins structure and set the 
// margins for the report.
margins = rd.PrintOptions.PageMargins;
margins.bottomMargin = 350;
margins.leftMargin = 600;
margins.rightMargin = 350;
margins.topMargin = 300;
// Apply the page margins.
rd.PrintOptions.ApplyPageMargins(margins);

所以上面的工作正常。我们只需要获取报表文档页面边距,并在其中设置边距,而不是新的 PageMargins 对象的初始化。

So the above is working fine. We just need to get the report document page margins and set the margins there instead of new initialization of PageMargins object.

这篇关于在水晶报表中以编程方式设置页边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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