PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 7:47 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Mar 26, 2013 1:41 pm 
Offline

Joined: Tue Mar 26, 2013 12:07 pm
Posts: 3
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!


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 26, 2013 2:17 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Hi!
Code:
R1.KeepWith = R5.Index - R1.Index -2;
Why "-2"?
You exclude R5 and the last R4 row from the KeepWith.

Use "-1" if R5 is just a filler or "-0" to include R5 in the KeepWith block.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 28, 2013 11:02 am 
Offline

Joined: Tue Mar 26, 2013 12:07 pm
Posts: 3
Thomas Hoevel wrote:
Hi!
Code:
R1.KeepWith = R5.Index - R1.Index -2;
Why "-2"?
You exclude R5 and the last R4 row from the KeepWith.

Use "-1" if R5 is just a filler or "-0" to include R5 in the KeepWith block.

Hi,

at first, thanks for the help, i use -2 to make sure that there is no overlapping in my code, but it doesn't matter.
You are right if i want to make it work the right way it should be: 'R5.Index - R1.Index'.

Any Ideas why it doenst work properly? there can be a pagebreak every line no matter to which value i set the keepwith.
My only thought is it is because of "pakeha_by" version, i need that because the normal migradoc can't handle well
tables with large numbers of rows.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 28, 2013 12:41 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Senser wrote:
My only thought is it is because of "pakeha_by" version
Try the "official" version and if KeepWith works (and AFAIK it does work), then the problem is with the "pakeha_by" version.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 28, 2013 1:06 pm 
Offline

Joined: Tue Mar 26, 2013 12:07 pm
Posts: 3
Thomas Hoevel wrote:
Senser wrote:
My only thought is it is because of "pakeha_by" version
Try the "official" version and if KeepWith works (and AFAIK it does work), then the problem is with the "pakeha_by" version.


yes, that seems to be the problem, unfortunately i need the pakeha_by version because otherwise the rendering
takes too long (2-3 minutes). But i am working on a solution which counts how many rows fit on a single page and adds
a "breakrow" which has a given height.


thanks for the help!


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 19, 2013 6:46 am 
Offline

Joined: Wed Jan 19, 2011 5:34 am
Posts: 19
Senser wrote:
unfortunately i need the pakeha_by version because otherwise the rendering
takes too long (2-3 minutes)


Hi Senser

I've just noticed you've got the problem with my patch. I can have a look in nearest days if you still need help with it.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 14, 2013 6:20 am 
Offline

Joined: Wed Jan 19, 2011 5:34 am
Posts: 19
In case somebody needs KeepWith property to work I've updated patched assemblies: http://www.pakeha_by.my-webs.org/MigraDocFastTableRender.html


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 21, 2014 11:00 am 
Offline

Joined: Tue Mar 04, 2014 9:56 am
Posts: 9
Hi, I am not using source safe so how do I apply this patch to my migradoc code??


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 137 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group