Hello,
I am receiving this error message when I try to convert a document to a PDF:
This exception was originally thrown at this call stack:
System.Drawing.Graphics.MeasureString(string, System.Drawing.Font, System.Drawing.PointF, System.Drawing.StringFormat)
Syncfusion.DocIO.Rendering.DrawingContext.MeasureString(string, System.Drawing.Font, System.Drawing.StringFormat, Syncfusion.DocIO.DLS.WCharacterFormat, bool, bool, Syncfusion.Office.FontScriptType)
Syncfusion.Layouting.MathLayoutContext.LayoutDelimiterSwitch(System.Drawing.RectangleF, Syncfusion.Layouting.LayoutedOMathWidget, Syncfusion.Office.IOfficeMathFunctionBase)
Syncfusion.Layouting.MathLayoutContext.LayoutOfficeMathFunctions(System.Drawing.RectangleF, Syncfusion.Layouting.LayoutedOMathWidget, Syncfusion.Office.IOfficeMathBaseCollection)
Syncfusion.Layouting.MathLayoutContext.LayoutOfficeMath(System.Drawing.RectangleF, Syncfusion.Office.IOfficeMath)
Syncfusion.Layouting.MathLayoutContext.LayoutFractionSwitch(System.Drawing.RectangleF, Syncfusion.Layouting.LayoutedOMathWidget, Syncfusion.Office.IOfficeMathFunctionBase)
Syncfusion.Layouting.MathLayoutContext.LayoutOfficeMathFunctions(System.Drawing.RectangleF, Syncfusion.Layouting.LayoutedOMathWidget, Syncfusion.Office.IOfficeMathBaseCollection)
Syncfusion.Layouting.MathLayoutContext.LayoutOfficeMathCollection(System.Drawing.RectangleF, Syncfusion.Layouting.LayoutedMathWidget, Syncfusion.Office.IOfficeMaths)
Syncfusion.Layouting.MathLayoutContext.Layout(System.Drawing.RectangleF)
Syncfusion.Layouting.LCContainer.DoLayoutChild(Syncfusion.Layouting.LayoutContext)
Can you lend any insight into why this might be happening or what it pertains to?
Thanks!
Hi Natalie,
We suspect that you are facing an issue
while converting a Word document with mathematical equation to PDF. We tried to
reproduce the reported problem with the mathematical equations, but it works
properly on our end. For your reference, we have attached the sample
application which we used at our end to reproduce the reported problem and it
can be downloaded from the below attachment.
Can you please try our sample application at your end using your Word document?
If you are still facing the issue means, we suspect that the issue might be due
to the input Word document. So, kindly share the input Word Document to
reproduce the reported issue.
Note: If you have any confidential data in your input Word document,
please replace with some dummy data and provide us the same. We just need your
document to recreate the problem you face. So, once investigated the issue, we
will delete the document permanently from our side and do not share with
anyone.
If you are doing some other
process in the code, please modify the sample attached and share it
as issue reproducible sample. Thereby, we will proceed further to replicate the
same problem at our end and will provide the more details at the earliest.
Regards,
Akash.
Attached is the word document that I am having the issue with displaying.
If I first save the document as a word document, open it as a FIleStream, create a WordDocument from the FileStream, and then convert it to a PDF, the error message is not thrown. It is only thrown when I create the WordDocument programmatically and then try to convert to PDF using the following code:
WordDocument document = BuildSyncfusionReport(serviceProvider, documentInfo);
using (DocToPDFConverter converter = new())
{
converter.Settings = new DocToPDFConverterSettings() { ExportBookmarks = ExportBookmarkType.Bookmarks };
//Converts Word document into PDF document
using (PdfDocument pdfDocument = converter.ConvertToPDF(document))
{
//Saves the PDF document
pdfDocument.Save(fileName);
}
};
Attachment: SyncfusionReport_8e151be1.zip
Natalie, as you mentioned that the issue occurs only when
you create the Word document programmatically and then convert it to PDF, kindly
share the code that is used inside the BuildSyncfusionReport method to prepare
similar document on our end and reproduce the issue.
In the input Word document we can find multiple equations and contents.
If you are facing difficulties to share the entire code, comment out some part
of the implementation and narrow down the part of the code which causes the
issue. Now share the simplified code snippet. Thereby, we will proceed further
to replicate the same problem at our end and will provide the details at
the earliest.
I have attached a project in which the error can be reproduced. It seems to be
Natalie, we have reproduced the reported problem “Exception is thrown while converting a Word document with Equation to PDF” on our end. We will validate this issue and update you with more details by the starting of next week.
Natalie, we have confirmed that the reported issue “Argument
Exception is thrown while converting a Word document to PDF with MathML
Equation” is a defect and we have logged a
defect report. We will include the fix for this defect in our Weekly
NuGet release which is estimated to be available
on the end of February 2024.
The status of this bug can be tracked through the below link:
https://www.syncfusion.com/feedback/50797/argument-exception-is-thrown-while-converting-a-word-document-to-pdf-with-mathml
Disclaimer: “Inclusion of this solution in the weekly release may change due to
other factors including but not limited to QA checks and works
reprioritization.”
Natalie, as promised earlier, we have included the fix for the
reported bug with “Argument Exception is thrown while converting a Word document to
PDF with MathML Equation” in our latest weekly NuGet release (v24.2.8).
Root cause of the issue:
1. Reported ArgumentException is thrown while measuring the MathML text with a disposed font object
When updating the TOC or document fields, internally we are performing our own layouting algorithm to find the page numbers of the document.
Here, the MathML font object gets disposed after the first layouting (UpdateTableOfContents) process.
So, when we try to measure the MathML text a second time (UpdateTableOfContents) with a disposed font object, we face this ArgumentException.
Please use the below link to download our
latest weekly NuGet:
https://www.nuget.org/packages/Syncfusion.DocToPDFConverter.Wpf/24.2.8
The status of this bug task can be tracked
through the below link:
https://www.syncfusion.com/feedback/50797/argument-exception-is-thrown-while-converting-a-word-document-to-pdf-with-mathml
Note:
We will include this fix in our 2024 Volume 1
Main release, which will be available in the end of March 2024.