PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 4:12 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Mar 01, 2010 5:10 pm 
Offline

Joined: Wed Feb 10, 2010 3:49 pm
Posts: 10
Hi there,

I'm am completely at a loss with a problem I am having with MigraDoc at the moment. I will try my best to explain, but please ask if you need anymore information. Sometimes when I call PdfDocumentRenderer's RenderDocument function, I am getting a NullReferenceException (Object reference not set to an instance of an object). I have managed to narrow this down to being something to do with when I'm adding a table to a section.

It makes no sense to me what so ever. The problem is intermittent and the same code is used everytime it is called. It can be called 8 times in the same document and work 7 of those times! By process of elimination, this line of code is what seems to be the cause of the exception:

Code:
table = section.AddTable();
(where table is of type Table and section of type Section).

And the code that actually throws the exception is (on the pdfRender.RenderDocument() line):

Code:
MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document;
            pdfRender.RenderDocument();


Any idea's or suggestions you may have would be massively appreciated as I am now fresh out of ideas!

Thanks in advance,
Sarah


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2010 8:54 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi, Sarah,

our application uses a lot of tables - and rendering works 10 out of 10 times.

In Visual Studio, click Exceptions in the Debug menu and check Common Language Runtime Exceptions in the Thrown column.

Then you'll see where the exception is thrown. This may help us further.

The exception relates to the contents of your table.
There's nothing wrong with the source lines you show us. The problems come from the lines you don't show ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2010 9:11 am 
Offline

Joined: Wed Feb 10, 2010 3:49 pm
Posts: 10
Thanks for your reply Thomas. I've checked the Throw box in the debug menu but it's stopped in the same place on RenderDocument. I'm guessing I need to load the MigraDoc project so I can go into that code as at the moment I am just using the DLL's so I can't step into them or anything. I will give that a go now and let you know how I get on.

I thought it may have been the data I was putting in the table, so I tried drawing the table without giving it any data and it still gave me the error. My application creates a report based on date ranges, and here's the really strange thing! If I try and create it for 22nd March 09 - 01st April 09, it will fail to draw this one table which has 3 rows of information. It will draw other tables using the same code no problem. If I try and create it for 23rd March 09 - 01st April 09 it will work and draw the table, and the table has exactly the same data plus an extra row of new data for the 23rd. However I know it's not down to the number of rows, as the same code will draw a table with 1, 2 or 3 rows in other cases without any problems.

Anyway, I'll let you know how I get on with debugging! Thanks again :)


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2010 9:25 am 
Offline

Joined: Wed Feb 10, 2010 3:49 pm
Posts: 10
Ok so the exception is being thrown on this line:

probeHeight = (XUnit)this.bottomBorderMap[probeRow + 1] - offset;

Which is in TableRenderer. None of the variables are null though, they all show a value. I really appreciate your help! Please let me know if you need any more information.

Thanks,
Sarah.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2010 9:28 am 
Offline

Joined: Wed Feb 10, 2010 3:49 pm
Posts: 10
Here's the stack trace in case that helps...

at MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo) in \MigraDoc\PDFSharp-MigraDocFoundation-1_31\MigraDoc\code\MigraDoc.Rendering\MigraDoc.Rendering\TableRenderer.cs:line 328


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2010 9:55 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Plain vanilla tables work - so there must be something unusual in your table code.

Do you use MergeDown?
There's a known problem with certain combinations of MergeDowns.

An MDDDL file of your document could help.
http://www.pdfsharp.net/wiki/MigraDocDDL.ashx

You can attach a ZIP to this thread or send it via PM.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2010 10:58 am 
Offline

Joined: Wed Feb 10, 2010 3:49 pm
Posts: 10
Thanks Thomas. I have attached the DDL. I'm not using a merge down in this table but I am using a merge right. The DDL attached is only creating the table that is causing the problems. If you like me to create another one where it also creates a table successfully, please let me know.

Thanks again,
Sarah


Attachments:
ReportMDDDL.zip [1.18 KiB]
Downloaded 306 times
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 03, 2010 2:38 pm 
Offline

Joined: Wed Feb 10, 2010 3:49 pm
Posts: 10
I think I may have solved it! I'm using the keep with property so that if it can't draw a certain amount of rows on a page, it will start the table on a new page. My original code was:
Code:
if (table.Rows.Count < 5)
                table.Rows[0].KeepWith = table.Rows.Count - 1;
            else
                table.Rows[0].KeepWith = 5;

I noticed in the MDDDL file that I sent you, compared with one that was successful that this was different and commented out the keep with code, and the table that was originally failing worked. So I tried changing the code to the following:
Code:
if (table.Rows.Count <= 5)
                table.Rows[0].KeepWith = table.Rows.Count - 1;
            else
                table.Rows[0].KeepWith = 5;

And it worked! It'll require a lot more testing but fingers crossed. I'll let you know how I get on. If you have any suggestions on how to improve my use of the keep with property to make my code more robust, all suggestions are gratefully received :)

Thanks,
Sarah


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 03, 2010 2:47 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Code:
table.Rows[0].KeepWith = 5;

requires 6 rows in the table.
So the old code will always fail if there are 5 rows in the table.

Thank you for the feedback.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 395 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