- Home
- Forum
- ASP.NET Core - EJ 2
- problem when I convert a word document to pdf
problem when I convert a word document to pdf
Hello
I am using an application c# to convert
I use an application to convert a word file to pdf. the application works all the time, except with this word template
here are the necessary elements.
Thank you for your help
My Code
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
newRelativeFilePath = "C:\\13319\\ContratDeSousTraitance\\A79F7AD0-D12B-4D33-B1F6-8188D36508DC\\templateOutput\\ba2f2773-87b0-488f-a82e-3a1c6b74bb9e.docx";
//Open the file as Stream
using (FileStream fileStream = new FileStream(Path.GetFullPath(newRelativeFilePath), FileMode.Open))
{
//Loads an existing Word document.
using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic))
{
//Creates an instance of DocIORenderer.
using (DocIORenderer renderer = new DocIORenderer())
{
//Sets Chart rendering Options.
renderer.Settings.ChartRenderingOptions.ImageFormat = Syncfusion.OfficeChart.ExportImageFormat.Jpeg;
renderer.Settings.EmbedFonts = true;
renderer.Settings.EmbedCompleteFonts = true;
//Converts Word document into PDF document.
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
{
//Saves the PDF file to file system.
using (FileStream outputStream = new FileStream(Path.GetFullPath(newRelativeFilePathPdf), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
if (data!.ContainsKey("annexes"))
{
AddAnnexes(JArray.Parse(data["annexes"].ToString()), pdfDocument);
}
pdfDocument.Save(outputStream);
}
}
}
}
Error
voici l'erreur à Syncfusion.Layouting.LCContainer.UpdateExpressionField(IWidget childWidget)
à Syncfusion.Layouting.LCContainer.CreateNextChildContext()
à Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)
à Syncfusion.Layouting.LCLineContainer.DoLayoutChild(LayoutContext childContext)
à Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)
à Syncfusion.Layouting.LCContainer.DoLayoutChild(LayoutContext childContext)
à Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)
à Syncfusion.Layouting.LeafLayoutContext.LayoutTextBoxBody()
à Syncfusion.Layouting.LeafLayoutContext.Layout(RectangleF rect)
à Syncfusion.Layouting.LCContainer.DoLayoutChild(LayoutContext childContext)
à Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)
à Syncfusion.Layouting.LCLineContainer.DoLayoutChild(LayoutContext childContext)
à Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)
à Syncfusion.Layouting.LCContainer.DoLayoutChild(LayoutContext childContext)
à Syncfusion.Layouting.LCContainer.Layout(RectangleF rect)
à Syncfusion.Layouting.Layouter.Layout(IWidgetContainer widget, ILayoutProcessHandler handler, DrawingContext dc)
à Syncfusion.DocIO.DLS.Rendering.DocumentLayouter.LayoutHeaderFooter()
à Syncfusion.DocIO.DLS.Rendering.DocumentLayouter.Syncfusion.Layouting.ILayoutProcessHandler.GetNextArea(RectangleF& area, Int32& columnIndex, Boolean& isContinuousSection, Boolean isSplittedWidget, Single& topMargin, Boolean isFromDynmicLayout, IWidgetContainer& curWidget)
à Syncfusion.Layouting.Layouter.Layout(IWidgetContainer widget, ILayoutProcessHandler handler, DrawingContext dc)
à Syncfusion.DocIO.DLS.Rendering.DocumentLayouter.LayoutPages()
à Syncfusion.DocIO.DLS.Rendering.DocumentLayouter.Layout(IWordDocument doc)
à Syncfusion.DocIORenderer.DocIORenderer.ConvertToPDF(WordDocument wordDocument)
à TeePee.Document.Generator.DocumentEditor.Generate(String output, String path, Boolean IsRelativePath, IDictionary`2 data, String host, User user, JObject context, Nullable`1 returnNativeFormat, String beginExp, String endExp) dans C:\Users\ahmed\projects\API\TeePeeDocumentGenerator\TeePee.Document.Generator\DocumentEditor.cs :ligne 124
Attachment: output_ad54cb0.zip
Hi Aitbouhou,
We have reproduced the reported problem “System.NullReferenceException
while converting Word document to PDF” in our end. We will validate the issue and provide
you with more details within two days.
Regards,
Dharanya.
Aitbouhou, we have
confirmed that the reported issue “NullReferenceException
throws while converting a Word document to PDF with fields” 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 mid of December 2024.
The status of this bug can be tracked through the feedback
link.
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.”
Hello
Any news about this ?
Thank you
Aitbouhou, as promised earlier, we have included the fix for the reported issue with “NullReferenceException throws while converting a Word document to PDF with fields” in our latest weekly NuGet release (v28.1.35).
Root cause of the issue:
The input document contains fields within text boxes located in the footer. During the Word to PDF conversion, we mistakenly set the layout information of the fields to null, which resulted in the reported issue.
Please use the below link to download our latest weekly NuGet:
Syncfusion.DocIORenderer.Net.Core
The status of this bug can be tracked through the below link:
NullReferenceException throws while converting a Word document to PDF with fields in ASP.NET Core | Feedback Portal
Note: You can also download our latest weekly NuGet release (v28.2.4) here.
- 4 Replies
- 4 Participants
-
AA Aitbouhou Adam
- Dec 2, 2024 04:43 PM UTC
- Feb 5, 2025 09:20 AM UTC