PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 3:33 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: KeepWith problem
PostPosted: Wed Mar 14, 2018 9:07 pm 
Offline

Joined: Wed Mar 14, 2018 8:47 pm
Posts: 2
Hello,
I'm creating an new report in C#. I have a table where two rows must be kept together. According to documentation, this can be done using row.KeepWith =2 ;
However when I run my application, the rendereDocument Method results in an exception. Specific a keynotfoundexception (The given key was not present in the dictionary)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo)
at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel)
at MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx)
at MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely)
at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages()
at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()
at BikeBillLibrary.Helpers.DocumentHelper.CreatePDF(DocumentModel doc) in K:\\Data\\Dropbox\\netProjects\\BikeBillNew\\BikeBillLibrary\\Helpers\\DocumentHelper.cs:line 142
at BikeBillLibrary.ViewModels.FactuurKlantViewModel.MaakFactuur() in K:\\Data\\Dropbox\\netProjects\\BikeBillNew\\BikeBillLibrary\\ViewModels\\FactuurKlantViewModel.cs:line 362
at BikeBillUI.Views.FactuurKlant.Factuur_Executed(Object sender, ExecutedRoutedEventArgs e) in K:\\Data\\Dropbox\\netProjects\\BikeBillNew\\BikeBillUI\\Views\\FactuurKlant.xaml.cs:line 82"

When I comment 'row.KeepWith=2;' out, the RenderDocument executes fine!

I've installed PDFSharp-MigraDoc-wpf from buget, version 1.50.4790-beta5a


Top
 Profile  
Reply with quote  
 Post subject: Re: KeepWith problem
PostPosted: Wed Mar 14, 2018 9:24 pm 
Offline

Joined: Wed Mar 14, 2018 8:47 pm
Posts: 2
The problem is probably that I have an odd number of rows in my table. My table consist of a header row followed by items , in pair of two rows.
So I want to keep the pair of two rows together on a page. Therefore I've set my KeepWith=2 on the first row AFTER the header row. However, since this is in a loop, the KeepWith is being set on each new pair of two rows...

Code:
           
            table = section.AddTable();
            table.Rows.LeftIndent = 0;
            var column = table.AddColumn("13cm");
            column = table.AddColumn("1.5cm");
            column = table.AddColumn("2.5cm");
            column = table.AddColumn("2.5cm");

            // Create the header of the table.
            var row = table.AddRow();
            row.HeadingFormat = true; // repeat on each page
            row.Borders.Bottom.Width = 0.25;
            row.Cells[0].AddParagraph("Artikelomschrijving");
            row.Cells[1].AddParagraph("Aantal");
            row.Cells[2].AddParagraph("Artikelprijs");
            row.Cells[3].AddParagraph("Arbeidsloon");

            foreach (DocumentDetailModel item in _doc.DocumentDetails)
            {
                // first row of 2
                row = table.AddRow();
                row.KeepWith = 2;
                row.Cells[0].AddParagraph(item.Artikelomschrijving);
                row.Cells[1].AddParagraph(item.Aantal.ToString());
                row.Cells[2].AddParagraph($"{(item.Artikelprijs * item.Aantal).ToString("0.00")} €");
                row.Cells[3].AddParagraph($"{item.Arbeidsloon.ToString("0.00")} €");

                // second row
                row = table.AddRow();
                if (item.Artikelomschrijvingdetail!=null && item.Artikelomschrijvingdetail.Trim()!=String.Empty)
                {
                    row.Cells[0].AddParagraph(item.Artikelomschrijvingdetail);
                }               
            }


Top
 Profile  
Reply with quote  
 Post subject: Re: KeepWith problem
PostPosted: Wed Mar 14, 2018 10:40 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 905
Location: CCAA
Hi!
edwardkoks wrote:
According to documentation, this can be done using row.KeepWith =2 ;
Where is that documentation?

To keep two rows together, you have to write "KeepWith = 1". You count the rows you attach to the current row.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 28 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group