Hi support,
I have a word document (docx) with a header and an image placed in the header. When i convert the document to html and back to docx it creates a top margin which it shouldn’t.
The before (fejltest.docx) and after file (convertedfiletest.docx) is added to this post.
Here is the code,
Document documentFromHtml;
Document documentWord;
var license = new Aspose.Words.License();
license.SetLicense("Aspose.Words.lic");
var fileBytes = File.ReadAllBytes("fejltest.docx");
// create a word document
using (var inStream = new MemoryStream(fileBytes))
{
documentWord = new Document(inStream, new LoadOptions(LoadFormat.Docx, null, null));
}
// Convert to html
var htmlDocument = HttpUtility.HtmlDecode(documentWord.ToString(SaveFormat.Html));
// Save to docx again
using (var memstream = new MemoryStream(Encoding.Unicode.GetBytes(htmlDocument)))
{
var loadOptions = new LoadOptions { LoadFormat = LoadFormat.Html };
documentFromHtml = new Document(memstream, loadOptions);
}
documentFromHtml.Save("c:\temp\convertedfiletest.docx", SaveFormat.Docx);
Best Regards,
Jakob Petersen
Team Lead
Edora A/S