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
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)