Error importing DocX

0 Answers 23 Views
General Discussions WordsProcessing
Jamie
Top achievements
Rank 1
Jamie asked on 20 Feb 2025, 05:10 PM

Can someone help me figure out what is wrong here?  I'm getting ad horribly vague Null exception.

 

var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
RadFlowDocument document = new RadFlowDocument();
byte[] docBytes = File.ReadAllBytes(path);

document = docxProvider.Import(docBytes);    ERROR HERE

var resultBytes = pdfProvider.Export(document);

File.WriteAllBytes(resultPath, resultBytes);

 

The document i'm trying to load contains tables and images within the tables (jpeg barcodes)

I have verified that pretty much every other tool i use can read the file without issue. 

The goal is ultimately to export the file as a PDF.

 

Error details:

{"Object reference not set to an instance of an object."}

   at Telerik.Windows.Documents.Flow.FormatProviders.Docx.Model.Elements.Document.ParagraphPropertiesElement.OnAfterRead(IDocxImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase`3.OnAfterRead(IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Parts.OpenXmlPartBase.Import(IOpenXmlReader reader, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Parts.OpenXmlPartBase.Import(Stream stream, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.ImportPartFromArchive(ZipArchiveEntry zipEntry, PartBase part, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.Import(Stream input, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider.ImportOverride(Stream input)
   at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Import(Stream input)
   at Telerik.Windows.Documents.Common.FormatProviders.BinaryFormatProviderBase`1.Import(Byte[] input)
   at IVC_BIPS_Desktop.rfrmMain.ConverDocxToPdf(String path, String resultPath) in C:\Source\IVC Batch Instructions Printing\IVC_BIPS_Desktop\rfrmMain.cs:line 499
Yoan
Telerik team
commented on 24 Feb 2025, 02:16 PM

Hello Jamie,

Thank you for reaching out.

I am sorry to hear you are experiencing unexpected results. I would gladly like to help you with this case however without having reproduced and examine the same results on my end, my assistance is very limited.

With that in mind, in order for me to get a better context and understanding of the scenario you are experiencing, would you be able to share with us a sample document and project you are using to reproduce this behavior? This way I can try to achieve the same results on my end, investigate the issue further, try to identify the cause, and get back to you with details and feedback.

NOTE: Please keep in mind that this is a Q&A Forum thread and anything shared here will be publicly available. If you have any concerns, make sure you remove any sensitive data or replace it with a dummy one.

Thank you in advance for your cooperation. I am looking forward to your reply.

Regards,

Yoan

Bexel Consulting
Top achievements
Rank 1
Iron
Iron
commented on 26 Feb 2025, 01:35 PM

if you didnt manage to make i it work with byte array, this works for me:
i use overrload of Inport that take Stream as an argument

private RadFlowDocument ConvertDocxToRadFlowDocument(Stream contentStream)
{
    var docxProvider = new DocxFormatProvider();
    MemoryStream destination = new MemoryStream();
    RadFlowDocument document;

    contentStream.CopyTo(destination);
    document = docxProvider.Import(destination);

    return document;
}

you should get RadFlowDocument that you can then convert to PDF
Yoan
Telerik team
commented on 03 Mar 2025, 05:41 AM

Hello Velijko,

Thank you for taking the time to share your feedback! We truly appreciate your insights and your willingness to help other users by sharing your experience. Such efforts do not go unnoticed and are truly appreciated. I hope your insights prove helpful to others who may benefit from your experience.

Regards,

Yoan

No answers yet. Maybe you can help?

Tags
General Discussions WordsProcessing
Asked by
Jamie
Top achievements
Rank 1
Share this question
or