PdfProcessing library 2024.3.802 throws exception The document element is associated with another parent. (Parameter 'item')

1 Answer 108 Views
PdfProcessing WordsProcessing
Jason
Top achievements
Rank 1
Iron
Jason asked on 19 Aug 2024, 03:39 AM | edited on 19 Aug 2024, 10:33 AM

Greetings,

I am using Telerik 2024.3.802 PdfProcessing library.

We have used the Telerik library to convert a HTML document to Word DOCX format.

This process completes successfully.

Then using Telerik PdfProcessing, executing a Word to PDF process. 

The method throws an exception shown below.

The code is fairly trivial:

 

public static byte[] ConverDocxToPdf(byte[] docxBytes)
{
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();

var document = docxProvider.Import(docxBytes);

using var memoryStream = new MemoryStream();
pdfProvider.Export(document, memoryStream);
return memoryStream.ToArray();
}

 

If we open the Telerik produced docx file, in word, and resave it (no changes)

Then  the Word to PDF process works. So it may imply there is an error in the HTML to word conversion which is creating a invalid docx file.

Is there anyway to "validate" a docx file with the Telerik tooling?

 

EDIT: When using this OpenXML validator: https://learn.microsoft.com/en-us/office/open-xml/word/how-to-validate-a-word-processing-document?tabs=cs-0%2Ccs  against the Telerik created word docx file, I get a list of 51 errors.  So Telerik Html to Docx perhaps is not creating a valid docx for various nodes.

 

Here are the list of errors

 

Error 1
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:footerReference'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.SectionProperties
Error 2
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 3
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 4
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 5
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 6
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 7
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 8
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 9
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 10
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 11
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 12
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 13
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 14
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 15
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 16
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 17
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 18
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 19
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 20
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 21
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 22
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 23
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 24
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 25
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 26
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 27
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 28
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 29
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 30
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 31
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 32
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 33
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 34
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 35
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 36
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 37
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 38
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 39
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 40
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties

 

 

(Microsoft.AspNetCore.Components.Web.ErrorBoundary) Unhandled exception rendering component: "The document element is associated with another parent. (Parameter 'item')"
System.ArgumentException: The document element is associated with another parent. (Parameter 'item')
at Telerik.Windows.Documents.Fixed.Model.Collections.DocumentElementCollection`2.VerifyDocumentElementOnInsert(T item)
at Telerik.Windows.Documents.Core.Data.DocumentElementCollectionBase`2.Add(T item)
at Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor.Append(PositionContentElement element)
at Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor.Draw(PositionContentElement element)
at Telerik.Windows.Documents.Fixed.Model.Editing.Layout.ContentElementLayoutElementBase`1.Draw(DrawLayoutElementContext context)
at Telerik.Windows.Documents.Fixed.Model.Editing.Block.Draw(IEnumerable`1 lineElements, DrawLayoutElementContext context)
at Telerik.Windows.Documents.Fixed.Model.Editing.Block.DrawInternal(FixedContentEditor editor, Rect boundingRect)
at Telerik.Windows.Documents.Fixed.Model.Editing.Block.Draw(FixedContentEditor editor, Rect boundingRect)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.TableCell.Draw(FixedContentEditor editor)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawCellContent(FixedContentEditor editor, TableCell cell)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawTableCells(FixedContentEditor editor, Int32 rowIndex, TableCellCollection cells)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawTableRows(FixedContentEditor editor)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawInternal(FixedContentEditor editor, Rect boundingRect)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.Draw(FixedContentEditor editor, Rect boundingRect)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.TableCell.Draw(FixedContentEditor editor)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawCellContent(FixedContentEditor editor, TableCell cell)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawTableCells(FixedContentEditor editor, Int32 rowIndex, TableCellCollection cells)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawTableRows(FixedContentEditor editor)
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.DrawInternal(FixedContentEditor editor, Rect boundingRect)

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 20 Aug 2024, 06:50 AM

Hello Jason,

Thank you for the provided resources, detailed description of the scenario, and feedback from the investigation you have conducted. I am sorry to hear you are experiencing setbacks and would gladly like to assist you with this case, however without having any resources at my disposal which I can examine my assistance can be very limited.

With that in mind, would you be able to share with us the initial HTML document and code used for the whole conversion process? Having them at my disposal will allow me to reproduce the same scenario on my end and further investigate the cause.

Note: Please keep in mind that this is a public Q&A Forum so make sure you remove any sensitive information from the resources you decide to share.

Thank you in advance for your cooperation.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing WordsProcessing
Asked by
Jason
Top achievements
Rank 1
Iron
Answers by
Yoan
Telerik team
Share this question
or