PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Aug 19, 2018 11:26 pm

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 

Joined: Wed Mar 14, 2018 8:47 pm
Posts: 2
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

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

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...

            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;

            foreach (DocumentDetailModel item in _doc.DocumentDetails)
                // first row of 2
                row = table.AddRow();
                row.KeepWith = 2;
                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)

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

Joined: Sat Mar 14, 2015 10:15 am
Posts: 388
Location: CCAA
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
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)

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 5 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