I’m using C# to load a .docx file with Syncfusion DocIO, then convert it into the EJ2 DocumentEditor model via:
[HttpPost("Import")]
public IActionResult Import(IFormCollection data)
{
if (data.Files.Count == 0)
return BadRequest("No file uploaded.");
using var ms = new MemoryStream();
//
data.Files[0] is a DocIo DocX document
data.Files[0].CopyTo(ms);
ms.Position = 0;
var ext = Path.GetExtension(data.Files[0].FileName).ToLowerInvariant();
var doc = WordDocument.Load(ms,
ext switch
{
".docx" => FormatType.Docx,
".doc" => FormatType.Doc,
".rtf" => FormatType.Rtf,
".txt" => FormatType.Txt,
".xml" => FormatType.WordML,
_ => throw new NotSupportedException(ext)
});
var sfdt = JsonConvert.SerializeObject(doc);
doc.Dispose();
return Content(sfdt, "application/json");
}
After this, editorDoc.Sections[i].HeadersFooters.Header (and FirstPageHeader/EvenHeader) are always empty, even though docIo.Sections[i].HeadersFooters.Header contains my header content. I’d like to preserve and display all headers/footers in the EJ2 editor. What am I missing, or is there a different API I should call to carry over headers and footers?
If there isn't any other way, I even prepare to add these headers manually, but I don't know how to add them to the EJ2 object. I got as far as this code:
using var docIo = new Syncfusion.DocIO.DLS.WordDocument(ms, Syncfusion.DocIO.FormatType.Docx);
using var saveStream = new MemoryStream();
docIo.Save(saveStream, Syncfusion.DocIO.FormatType.Docx);
docIo.Close();
saveStream.Position = 0;
var editorDoc = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(saveStream, FormatType.Docx);
// Iterate sections and grab the default header (or FirstPageHeader / EvenHeader etc.)
foreach (WSection section in docIo.Sections)
{
var header = section.HeadersFooters.Header; // default/odd-page header
var first = section.HeadersFooters.FirstPageHeader;
var even = section.HeadersFooters.EvenHeader;
foreach (var para in header.Paragraphs)
{
}
}
Thank you.
Hi Lion,
|
Query |
Details |
|
I’m using C# to load a .docx file with Syncfusion DocIO, then convert it into the EJ2 DocumentEditor model via: [HttpPost("Import")] public IActionResult Import(IFormCollection data) { if (data.Files.Count == 0) return BadRequest("No file uploaded."); using var ms = new MemoryStream(); // data.Files[0]
is a DocIo DocX document ms.Position = 0; var ext = Path.GetExtension(data.Files[0].FileName).ToLowerInvariant(); var doc = WordDocument.Load(ms, ext switch { ".docx" => FormatType.Docx, ".doc" => FormatType.Doc, ".rtf" => FormatType.Rtf, ".txt" => FormatType.Txt, ".xml" => FormatType.WordML, _ => throw new NotSupportedException(ext) }); var sfdt = JsonConvert.SerializeObject(doc); doc.Dispose(); return Content(sfdt, "application/json"); } After this, editorDoc.Sections[i].HeadersFooters.Header (and FirstPageHeader/EvenHeader) are always empty, even though docIo.Sections[i].HeadersFooters.Header contains my header content. I’d like to preserve and display all headers/footers in the EJ2 editor. What am I missing, or is there a different API I should call to carry over headers and footers?
|
Our Document Editor supports the Header/Footer created from DocIo.
https://ej2.syncfusion.com/aspnetcore/documentation/document-editor/header-footer
Query: editorDoc.Sections[i].HeadersFooters.Header (and FirstPageHeader/EvenHeader) are always empty.
Details: If the ‘Link to Previous’ option is enabled for the header/footer of the document, ‘editorDoc.Sections[i].HeadersFooters.Header (and FirstPageHeader/EvenHeader)’ for some sections will be empty .
Also, we suspect that the reported problems are might be due to the contents in the input word document which used at your end. We need to investigate with the contents in your input Word document to reproduce the exact problem at our end. So, could you please provide us the input Word document which used at your end and also share the details of issue if you faced any in console, detailed replication procedure, video demonstration and code snippet. Thereby, we will analyse further and provide you the appropriate solution at the earliest.
Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.
|
Regards,
Akshaya
Hello,
Thank you for your reply. I attached in a zip file - 3 files -
Hi Lion,
We have tried to reproduce the reported issue with opening the document using Import() API, but it works properly. We have shared the sample with the steps which we have tried to reproduce the issue.
Steps to run the sample.
Please try it and revert with detailed replication steps, modified sample, video demonstrating the issue if you still have concerns. These details will be helpful for us to investigate further and assist you with prompt solution.
Regards,
Akshaya
Thanks for the files, it is working in my side too.
But I was mistaken, the test file I sent before was saved in Word so it fixed the headers problems before the import.
I attached here another file, this one is not working even with your example.
Thanks.
Hi Lion,
We have reproduced the reported issue and are currently in the process of validating it. We will provide you the further details within two working days.
Regards,
Akshaya
Hi Akshaya,
Thanks for the update, I'll wait for your response.
Lion
Hi Lion,
We are currently experiencing an issue with the dependent component. Our team is in the process of validating this issue and will provide an update on July 8, 2025.
Regards,
Dhanush S
Hi Lion,
We have confirmed that the reported issue "Header content is not preserved properly when resaving a DOCX document” 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 29th July 2025
The status of this bug can be tracked through the below link:
https://www.syncfusion.com/feedback/68766/header-content-is-not-preserved-properly-when-resaving-a-docx-document
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.
Regards,
Dhanush S
Thank you for your support!
I want to add something that maybe is related and maybe not - if not, I can open a new post.
The display in the document editor and the docx is not the same in page by page.
Not by a small change but in a lot of rows. I want to know if it's because of that merge problem between DocIO to Document editor.
I added here a zip file with the document and two pictures - Word Docx display and Document Editor display of the same document.
In addition I add the Import and Save functions for the server and client (same result):
Server Import:
[HttpPost("Import")]
public IActionResult Import(IFormCollection data)
{
if (data.Files.Count == 0)
return BadRequest("No file uploaded.");
using var ms = new MemoryStream();
data.Files[0].CopyTo(ms);
ms.Position = 0;
var sfDoc = new Syncfusion.DocIO.DLS.WordDocument(ms, Syncfusion.DocIO.FormatType.Docx);
Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(sfDoc);
var sfdtJson = JsonConvert.SerializeObject(document);
document.Dispose();
return Content(sfdtJson, "application/json");
}
Server Save Word:
Syncfusion.DocIO.DLS.WordDocument wordDocument = new Syncfusion.DocIO.DLS.WordDocument(processedResult.FormattedStream, WFormatType.Docx);
MemoryStream stream = new MemoryStream();
wordDocument.Save(stream, Syncfusion.DocIO.FormatType.Docx);
wordDocument.Close();
Client Save Word:
//DocumentEditor editor
editor.save(`${this.file}.docx`, "Docx");
Hi Lion,
We can reproduce the reported issue "The display in the document editor and the docx is not the same in page by page" in the fourth page of the provided document, shared the video demonstrating the same. We will validate further on this and update you with more details on July 15, 2025.
If you are mentioning any other issues apart from this , revert with more details and the video demonstration. It will be helpful for us to provide you prompt solution.
Regards,
Akshaya
Hi Lion,
We have confirmed the reported issue `Layouting difference comparing to MS word because of alignment type is 'Exactly'' as a defect and logged a bug report. We will include this fix in our 2025 Volume 2 SP release which is expected on first week of August 2025.
You can track the status of the bug through the below feedback link:
Layout is not similar to MS Word in the document in JavaScript | Feedback Portal
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.”
Regards,
Aravind D
Hi Lion,
We have created a new forum for the issue 'Layouting difference comparing to MS word because of alignment type is 'Exactly' for better tracking. Kindly follow up for further updates in:
https://forumassist.syncfusion.com/197172
Please let us know if you need further assistance.
Regards,
Akshaya
Hi Lion,
We are glad to announce that our patch release (v30.1.42) has been rolled out successfully. In this release, we have added the fix for the reported issue 'Header content is not preserved properly when resaving a DOCX document'.
Please upgrade to the latest version of packages to resolve this issue:
NPM link:
https://www.npmjs.com/package/@syncfusion/ej2-documenteditor
https://www.npmjs.com/package/@syncfusion/ej2-react-documenteditor
https://www.npmjs.com/package/@syncfusion/ej2-angular-documenteditor
NuGet links:
https://www.nuget.org/packages/Syncfusion.Ej2.Wordeditor.ASPNet.Core/
https://www.nuget.org/packages/Syncfusion.Ej2.Wordeditor.ASPNet.MVC5/
CDN link:
https://cdn.syncfusion.com/ej2/30.1.42/dist/ej2.min.js
Feedback link:
Regards,
Dhanush S
Hello,
Thank you for your efforts. It did fixed the problem! Now I can see the headers in the document editor and can save them.
I did find another issue, let me know if it's easy to solve -
When I have sections in the word file, for different headers in different sections, the page numbering is not consistent with the Word document.
In Word Docx the page number is 7 (correct) but in the document editor is 2 (wrong).
I attached an example for you to check - if you will load it to the document editor you will get in the second section page 2, but in the Docx, the first number in the second section is 7.
Thank you.
Hi Lion,
We have reproduced the reported issue 'the page numbering is not consistent with the Word document' and are currently in the process of validating it. We will provide you with further updates by August 13, 2025.
Regards,
Akshaya
Hi Lion,
For better tracking we have created new forum for the issue "the page numbering is not consistent with the Word document". Kindly follow that for further updates.
https://forumassist.syncfusion.com/197322
Regards,
Akshaya