Page Margins and Size Lost When Converting DOCX to HTML and Back to DOCX

Hello Aspose Team,

I am experiencing an issue with the conversion process using Aspose.Words. I have a DOCX document that I convert to HTML, and then I take the generated HTML and convert it back to a DOCX file. However, I am noticing that the page margins and page size of the original DOCX are not preserved in the final DOCX file after the round-trip conversion.

Overview of My Workflow:

  1. Initial Conversion (DOCX to HTML):
  • I start with a DOCX file and use HtmlSaveOptions to convert it to HTML.
  • The conversion works as expected, and the HTML file is generated correctly.
  1. Reconversion (HTML to DOCX):
  • I load the generated HTML using HtmlLoadOptions.
  • I save it as a DOCX file.

Problem: After converting the HTML back to DOCX, I notice that the page margins and page size differ from those in the original DOCX document. This discrepancy affects the formatting and layout of the document.

Attached Files:

  • Original DOCX: The source document with the correct page margins and size.
  • Converted HTML: The HTML file generated from the original DOCX.
  • Output DOCX: The final DOCX file after converting the HTML back to DOCX, showing the altered page margins and size.

ConversionHtmlDocxIssue.zip (613.7 KB)

Is there a way to ensure that the page margins and page size are retained when performing a round-trip conversion from DOCX to HTML and back to DOCX?

Thank you in advance for your assistance.

@gabriel.vega You can specify HtmlSaveOptions.ExportPageSetup property to preserve page setup after document roundtrip.

Document doc = new Document(@"C:\Temp\in.docx");
            
HtmlSaveOptions opt = new HtmlSaveOptions();
opt.PrettyFormat = true;
opt.ExportPageSetup = true;
doc.Save(@"C:\Temp\tmp.html", opt);

doc = new Document(@"C:\Temp\tmp.html");
doc.Save(@"C:\Temp\out.docx");

But you should note, that Aspose.Words is designed to work with MS Word documents. HTML documents and MS Word documents object models are quite different and it is not always possible to provide 100% fidelity after conversion one model to another.