Generally, when the records are rendered on a C1PrintDocument, they adjust according to the page size and if there is not much space available, the content is split across pages. In this walkthrough, lets discuss how positioning of the data can be done based on the available space on the pages in C1PrintDocument. This approach is useful where you would want to display a particular set of records on a single page depending on the available space on that page instead of splitting it across pages.
On the basis of the value returned by AvailableBlockFlowHeight, decide if the desired text, say, a RenderText, should start rendering from the current page itself or there should be a page break in between. The new page can be inserted using the NewPage method of the C1PrintDocument class.
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;
}
Please Note- The AvailableBlockFlowHeight property works only when the document is generated with using StartDoc()/EndDoc() methods.
Download the samples from the following links for detailed implementation: Download Sample- C# Download Sample-VB