C1PrintDocument基于页面大小生成

发布时间:2014/07/26 00:07 发布者:Alice

返回博客中心

一般来说,当记录是在c1printdocument描绘,他们根据调整页面大小计算,如果没有可用的页面空间,描绘的内容是按页面进行拆分。

在本文中,我们讨论在C1PrintDocument的可用的页面上,如何定位数据。这种方法可以由用户决定如何在页面的位置显示一组记录,而不是单纯的按页面进行拆分记录。

步骤如下:

1.使用StartDoc方法创建一个新的C1PrintDocment。

2.添加需要的数据,比如使用RenderBlock方法添加一个RenderTable到C1PrintDocment。

3.现在,使用C1PrintDocument类的AvailableBlockFlowHeight属性,在当前的页面区域设置垂直的一块区域。

4.基于AvailableBlockFlowHeight的返回值,决定是否请求文字,例如RenderText,应该从当前页面绘制还是在他们之间应该隔开。新页可以使用C1PrintDocument类的NewPage方法插入。

参考代码如下:

private void Form1_Load(object sender, EventArgs e)
{
  this.c1PrintDocument1.ResolvedUnit = UnitTypeEnum.Twip;
  this.c1PrintDocument1.DefaultUnit = UnitTypeEnum.Twip;
  c1PrintDocument1.AllowNonReflowableDocs = true;
  this.c1PrintDocument1.StartDoc();
  C1.C1Preview.RenderTable rt1 = new C1.C1Preview.RenderTable();
  C1.C1Preview.RenderText rt2 = new C1.C1Preview.RenderText();
  int row = 0;
  int col = 0;
  while ((row < 100))
  {
    col = 0;
    while ((col < 3))
    {
      rt1.Cells[row, col].Text = string.Format("Text in cell({0},{1})", row, col);
      rt1.Cells[row, col].Style.Borders.All = new LineDef(Color.Black);
      col += 1;
    }
    row += 1;
  }
  rt1.Style.Borders.All = new LineDef(Color.Black);
  col = 0;
  while ((col < 3))
  {
    rt1.Cols[col].Width = "1in";
    col += 1;
  }
  rt2.Text = "This is the text whose position is to be decided";
  rt2.Style.TextColor = Color.Red;
  c1PrintDocument1.RenderBlock(rt1);
  MessageBox.Show("Avaialable Height : " + this.c1PrintDocument1.AvailableBlockFlowHeight.ToString());
  RenderText rs = new RenderText();
  rs.Text = "test";
  double d = c1PrintDocument1.AvailableBlockFlowHeight;
  if (d > 3000)
  {
  }
  else
  {
    c1PrintDocument1.NewPage();
  }
  c1PrintDocument1.RenderBlock(rt2);
  this.c1PrintDocument1.EndDoc();
  c1PrintPreviewControl1.Document = c1PrintDocument1;
}

 

请注意:在使用StartDoc()/EndDoc()方法产生document的时候,AvailableBlockFlowHeight属性才会起作用。

本文Demo代码:

C1Report_AvailableBlockFlowHeight_CSharp.zip (17.17 kb)


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网