We’re having an issue with assembling a Word document from clauses that have Heading styles defined in them. The resulting Word document visually looks according to clauses that it was assembled from, but the Heading metadata doesn’t get carried over from the original clauses. This makes document headings not accessible to screen readers.
Make sure that botch clauses (“Disclaimer Page clause” and “Assumption & Notes clause”) have Headings defined.
Assemble the clauses into a new Word document
Verify that the resulting Word document doesn’t have the same heading styles as the original clauses, instead the styles for the heading are reset to “Normal” style
Actual Results:
This behavior prevents Screen-reading software (such as Windows Narrator) from identifying headings in the Word document which results in misinterpreted document content.
Expected Results:
The Heading styles should be carried over to the resulting document along with metadata that defines an element as a Heading.image1.jpg (37.4 KB) image2.jpg (40.1 KB)
@taeche Could you please attach your input and output documents along with the code used for assembling document? We will investigate the issue and provide you more information.
@taeche The problem occurs because you append your source document to the empty document create from scratch and use ImportFormatMode.KeepSourceFormatting. Even an empty document has it own built-in styles, like Heading 1 or Normal. Since you use ImportFormatMode.KeepSourceFormatting Aspose.Words converts formatting applied through the heading style in the source document to direct formatting applied to the paragraph and runs. This is done to preserve the original visual appearance of content after inserting content into the destination document.
Since both your documents have the same set of styles, you should use ImportFormatMode.UseDestinationStyles or ImportFormatMode.KeepDifferentStyles and use either empty clone of one of source document and a destination or the first document, like in the following simple code:
Document doc1 = new Document(@"C:\Temp\Assumption & Notes clause.docx");
Document doc2 = new Document(@"C:\Temp\Disclaimer Page clause.docx");
doc1.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles);
doc1.Save(@"C:\Temp\out.docx");
I’ve done some more investigation on this issue, please see my findings below:
To test I’ve created the following documents and assembled them using ImportFormatMode.KeepSourceFormatting because we are trying to determine if we can do the necessary fixes by starting with an empty document that has already been saved with the necessary formatting.
A Header/Footer document with content saved with the first line set to ‘Heading’ style:
FileName: HeaderFooterHeadingStyleSet
A Header/Footer document with content saved with the first line NOTset to ‘Heading’ style, instead set to ‘Normal’:
File name: HeaderFooterHeadingStyleNOTSet
First document with a heading that is set with ‘Heading’ style:
FileName: Disclaimer Page clause
Second document with a heading set with ‘Heading’ style:
FileName: Assumption & Notes
Test 1: (Repoducing the information you’ve provided above in your response)
Assemble a document containing:
HeaderFooterHeadingStyleNOTSet (Empty document saved with style set to ‘Normal’)
Assumption & Notes clause
Disclaimer Page clause
The documents are being assembled as follows:
Document doc1 = new Document(@"C:\Temp\HeaderFooterHeadingStyleNOTSet.docx");
Document doc2 = new Document(@"C:\Temp\Assumption & Notes clause.docx");
Document doc3 = new Document(@"C:\Temp\Disclaimer Page clause.docx");
doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);
doc2.AppendDocument(doc3, ImportFormatMode.KeepSourceFormatting);
This yields a document that appears to have headings by looking at the navigation pane, but the style set for the supposed headings is ‘Normal’ (@alexey.noskov, is this expected?):
Test 2:
Assemble a document containing:
HeaderFooterHeadingStyleSet_en-us (Empty document saved with style set to ‘Heading’)
Assumption & Notes clause_en-us
Disclaimer Page clause_en-us
Document doc1 = new Document(@"C:\Temp\HeaderFooterHeadingStyleSet.docx");
Document doc2 = new Document(@"C:\Temp\Assumption & Notes clause.docx");
Document doc3 = new Document(@"C:\Temp\Disclaimer Page clause.docx");
doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);
doc2.AppendDocument(doc3, ImportFormatMode.KeepSourceFormatting);
This yields a document that still appears to have headings SET but, the heading style set to ‘Normal’ style within the Styles window.
From what I’ve tested, it doesn’t matter if an empty document is used or if an empty document SET with the necessary format is used as source, the heading metadata is not persisted on the final document. Please let me know if you need more information on how I tested or if I should try something different.
@amjustin Could you please attach your test document here for testing? Also, have you tried to use ImportFormatMode.UseDestinationStyles? ImportFormatMode.KeepSourceFormatting should be used if you need to preserve visual appearance of the inserted content, but if you need to use the styles it is better to use ImportFormatMode.UseDestinationStyles so the same built-in style are applied to the inserted content.
@amjustin Thank you for additional information. I have managed to reproduce the problem with UseDestinationStyles and logged it as WORDSNET-24437. We will keep you informed and let you know once it is resolved.
In your case you should definitely use ImportFormatMode.UseDestinationStyles since you are appending several documents with headings and in the output document it is expected that all the headings from different document have the same heading style. This is possible only using ImportFormatMode.UseDestinationStyles.
Another option is using ImportFormatMode.KeepDifferentStyles, but in this case copy of styles are created in the destination document like Heading1_0, Heading1_1 etc.
Answering your questions:
This is expected, formatting is expanded to direct nodes formatting when you use ImportFormatMode.KeepSourceFormatting to preserve visual nodes appearance.
Unfortunately, using ImportFormatMode.UseDestinationStyles like I mentioned above would mess up the formatting of the final document. We will need to keep investigating the impact it would have on all of our use cases on content.
Is this WORDSNET-24437 an internal ticket? How can we keep track of this item?
@amjustin Yes, WORDSNET-24437 is an internal ticket. We will keep you informed regarding it’s status here in this thread and will be sure to inform you once it is resolved.
Currently the issue is in the queue for analysis.