【问题标题】:set page margins programmatically in crystal report在水晶报表中以编程方式设置页边距
【发布时间】:2015-10-04 05:46:19
【问题描述】:

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

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

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

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

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

以上对我不起作用。它不应用边距(当我从 Design -> Page Setup 静态设置边距时也是如此)。它显示的内容好像在动态使用时没有应用边距。我已附上图片以了解它是如何显示为预览的。

谁能帮我解决可能是什么问题?为什么没有应用边距?

【问题讨论】:

    标签: c# crystal-reports margin


    【解决方案1】:

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

    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 对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 2019-10-19
      • 2023-04-01
      相关资源
      最近更新 更多