At First i want to thank the migradoc/pdfsharp team for this awesome tool!
Now to my Problem,
I'm creating a kind of invoice pdf which is kind of complex because of the pagebreaks. It has a different Firstpage Footer and Header
and also a Table which fills multiple pages.
I Have multiple rows for each position on the table the best way to describe it, is with two foreach constructs:
Foreach(position)
#Name
#Description
Foreach(row in the position discription)
#Single row in the description
Endforeach
Endforeach
Each # stands for a row in my table.
I want to keep a whole position on one page so i use: "R1.KeepWith = R5.Index - R1.Index - 2;"
R1 is the first row of a position
R5 is the last row of a position
i hope this summs it a little bit up. The whole Table code is below:
Code:
Table Positionen = section.AddTable();
// create the item table
Positionen.Style = "table";
Positionen.Format.Font.Name = "Arial";
Positionen.Format.Font.Size = 7;
Positionen.Borders.Visible = false;
Positionen.Borders.Color = Colors.Black;
Positionen.Borders.Width = 0.25;
Positionen.Borders.Left.Width = 0.5;
Positionen.Borders.Right.Width = 0.5;
Positionen.Rows.LeftIndent = 0;
Positionen.LeftPadding = "0.1cm";//linker rand in den boxen
// Before you can add a row, you must define the columns
Column column2 = Positionen.AddColumn("12mm");
column2.Format.Alignment = ParagraphAlignment.Left;
column2 = Positionen.AddColumn("18mm");
column2.Format.Alignment = ParagraphAlignment.Left;
column2 = Positionen.AddColumn("55mm");
column2.Format.Alignment = ParagraphAlignment.Left;
column2 = Positionen.AddColumn("50mm");
column2.Format.Alignment = ParagraphAlignment.Right;
column2 = Positionen.AddColumn("15mm");
column2.Format.Alignment = ParagraphAlignment.Left;
column2 = Positionen.AddColumn("30mm");
column2.Format.Alignment = ParagraphAlignment.Left;
//Tableheader
Positionen.AddRow();
Positionen.Rows[0].Height = "0.75cm";
Positionen.Rows[0].VerticalAlignment = VerticalAlignment.Center;
//Positionen.Rows[0].Format.Font.Size = 8;
Positionen.Rows[0].Format.Font.Bold = true;
Positionen.Rows[0].Cells[0].AddParagraph("Item");
Positionen.Rows[0].Cells[1].AddParagraph("Quantity");
Positionen.Rows[0].Cells[2].AddParagraph("Description");
Positionen.Rows[0].Cells[3].AddParagraph("Price Clause");
Positionen.Rows[0].Cells[4].AddParagraph("Unit");
Positionen.Rows[0].HeadingFormat = true;//Setzen der Table Headers
Positionen.Rows[0].Borders.Visible = true;
Positionen.Rows[0].Cells[5].AddParagraph("Price per Unit");
Positionen.Rows[0].Cells[2].Borders.Right.Visible = false;
Positionen.Rows[0].Cells[3].Borders.Left.Visible = false;
bool alreadyfirstpagebreak = false;//var legt fest ob bereits der erste pagebreak durchgeführt wurde
foreach(DataRow dr in dtPosition.Rows)
{
if (alreadyfirstpagebreak == false)
{
Row R1 = Positionen.AddRow();//ERSTE POSITION ERSTE ZEILE
R1.Format.Font.Bold = true;
R1.Cells[0].AddParagraph(dr["PositionsNr"].ToString());
R1.Cells[1].AddParagraph(dr["Menge"].ToString());
R1.Cells[2].AddParagraph("Order-No.: " + dr["MaterialNr"].ToString());
R1.Cells[2].Borders.Right.Visible = false;
R1.Cells[3].Borders.Left.Visible = false;
R1.Cells[3].AddParagraph(dr["Preisart"].ToString());
R1.Cells[4].AddParagraph(dr["Einheit"].ToString());
R1.Cells[5].AddParagraph(dr["F-Preis"].ToString());
//R1.KeepWith = 3;
Row R2 = Positionen.AddRow();//ERSTE POSITION ZWEITE ZEILE
R2.Cells[2].MergeRight = 1;
R2.Format.Font.Bold = true;
R2.Cells[2].AddParagraph("Order-Desc.:");
//ERSTE BEZEICHNUNG
string[] sbez = dr["Bezeichnung"].ToString().Split('\n');
foreach (string s in sbez)
{
Row R4 = Positionen.Rows.AddRow();
R4.Cells[2].MergeRight = 1;
R4.Cells[2].AddParagraph(s);
#region ersterpagebreak//KOMPLEX!!!!
if (Positionen.Rows.Count == 42 && alreadyfirstpagebreak == false) //löst einen frühzeitigen pagebreak aus!
{ //Sehr wichtig da sonst der table auf der ersten seiten in den footer hineinreicht
Row RX = Positionen.AddRow();
RX.Height = "29mm";
RX.Borders.Visible = false;
alreadyfirstpagebreak = true;
}
else if (Positionen.Rows.Count == 43 && alreadyfirstpagebreak == false) //löst einen frühzeitigen pagebreak aus!
{ //Sehr wichtig da sonst der table auf der ersten seiten in den footer hineinreicht
Row RX = Positionen.AddRow();
RX.Height = "26mm";
RX.Borders.Visible = false;
alreadyfirstpagebreak = true;
}
else if (Positionen.Rows.Count == 44 && alreadyfirstpagebreak == false) //löst einen frühzeitigen pagebreak aus!
{ //Sehr wichtig da sonst der table auf der ersten seiten in den footer hineinreicht
Row RX = Positionen.AddRow();
RX.Height = "23mm";
RX.Borders.Visible = false;
alreadyfirstpagebreak = true;
}
else if (Positionen.Rows.Count == 45 && alreadyfirstpagebreak == false) //löst einen frühzeitigen pagebreak aus!
{ //Sehr wichtig da sonst der table auf der ersten seiten in den footer hineinreicht
Row RX = Positionen.AddRow();
RX.Height = "20mm";
RX.Borders.Visible = false;
alreadyfirstpagebreak = true;
}
else if (Positionen.Rows.Count == 46 && alreadyfirstpagebreak == false) //löst einen frühzeitigen pagebreak aus!
{ //Sehr wichtig da sonst der table auf der ersten seiten in den footer hineinreicht
Row RX = Positionen.AddRow();
RX.Height = "17mm";
RX.Borders.Visible = false;
alreadyfirstpagebreak = true;
}
#endregion
}
Row R5 = Positionen.Rows.AddRow();//Platz zwischen den Positionen
R5.Cells[2].MergeRight = 1;
R1.KeepWith = R5.Index - R1.Index - 2;
}
else
{
Row R1 = Positionen.AddRow();//ERSTE POSITION ERSTE ZEILE
R1.Format.Font.Bold = true;
R1.Cells[0].AddParagraph(dr["PositionsNr"].ToString());
R1.Cells[1].AddParagraph(dr["Menge"].ToString());
R1.Cells[2].AddParagraph("Order-No.: " + dr["MaterialNr"].ToString());
R1.Cells[2].Borders.Right.Visible = false;
R1.Cells[3].Borders.Left.Visible = false;
R1.Cells[3].AddParagraph(dr["Preisart"].ToString());
R1.Cells[4].AddParagraph(dr["Einheit"].ToString());
R1.Cells[5].AddParagraph(dr["F-Preis"].ToString());
//R1.KeepWith = 3;
Row R2 = Positionen.AddRow();//ERSTE POSITION ZWEITE ZEILE
R2.Cells[2].MergeRight = 1;
R2.Format.Font.Bold = true;
R2.Cells[2].AddParagraph("Order-Desc.:");
//ERSTE BEZEICHNUNG
string[] sbez = dr["Bezeichnung"].ToString().Split('\n');
foreach (string s in sbez)
{
Row R4 = Positionen.Rows.AddRow();
R4.Cells[2].MergeRight = 1;
R4.Cells[2].AddParagraph(s);
}
Row R5 = Positionen.Rows.AddRow();//Platz zwischen den Positionen
R5.Cells[2].MergeRight = 1;
R1.KeepWith = R5.Index - R1.Index -2;
}
}
Sorry for this long post but i have no clue what could be wrong :/
Thanks in advance!