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:14 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Jan 25, 2024 9:26 am 
Offline

Joined: Thu Jan 25, 2024 9:07 am
Posts: 1
Hello,

I have upgraded PDFsharp-MigraDoc NuGet package from version 1.5 to 6.0.0 (latest stable) in an ASP.NET application. A piece of old code, which used to work before, always fails with the new version. Our code loads a PDF template document with some pictures and inserts more content into it. Rendering a table using DocumentRenderer crashes with a InvalidOperationException exception.
I have isolated the issue. It's reproducible when I run this code in a console application in .NET8:

Code:
using FileStream templateFile = File.OpenRead("d:\\template.pdf");
PdfDocument templateDoc = PdfReader.Open(templateFile, PdfDocumentOpenMode.Modify);
PdfPage page = templateDoc.Pages[0];
XGraphics gfx = XGraphics.FromPdfPage(page);

Document doc = new();
Table table = doc.AddSection().AddTable();
table.AddColumn(Unit.FromCentimeter(5));
table.AddColumn(Unit.FromCentimeter(5));
table.AddColumn(Unit.FromCentimeter(5));

var row = table.AddRow();
row.Style = "Row";
row.Cells[0].AddParagraph("Cell1");
row.Cells[1].AddParagraph("Cell2");
row.Cells[2].AddParagraph("Cell3");

DocumentRenderer docRenderer = new(doc);
docRenderer.PrepareDocument();
docRenderer.RenderObject(gfx, XUnit.FromCentimeter(1.0), XUnit.FromCentimeter(11.0), "12cm", table);


Running it with PDFsharp-MigraDoc 6.0.0 or 6.1.0-preview-1 throws this exception:

Code:
Unhandled exception. System.InvalidOperationException: 'FieldInfos' must not be null here.
   at PdfSharp.Diagnostics.NRT.ThrowOnNull[TResult](String message)
   at MigraDoc.Rendering.FormattedCell.MigraDoc.Rendering.IAreaProvider.get_AreaFieldInfos()
   at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel)
   at MigraDoc.Rendering.FormattedCell.Format(XGraphics gfx)
   at MigraDoc.Rendering.TableRenderer.FormatCells()
   at MigraDoc.Rendering.TableRenderer.InitFormat(Area area, FormatInfo previousFormatInfo)
   at MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo)
   at MigraDoc.Rendering.DocumentRenderer.RenderObject(XGraphics graphics, XUnit xPosition, XUnit yPosition, XUnit width, DocumentObject documentObject)


The same code works fine with PDFsharp-MigraDoc ver. 1.5

Is there a bug in the new version?
Is there any better way to add a table into an existing document?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 29, 2024 7:17 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
JSvak wrote:
Is there a bug in the new version?
I think it's a bug.
Should be fixed with version 6.1.0-preview-2.

_________________
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  [ 2 posts ] 

All times are UTC


Who is online

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