We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Svg position in docx after converting from html

Hi! I’m having some trouble inserting my html into docx.
I created my html by this code

        var document = new Document("easy.docx");
        var saveOptions = new HtmlSaveOptions
        {
            ExportRoundtripInformation = true,
            SaveFormat = SaveFormat.Html,
            ExportImagesAsBase64 = true,
            ExportFontsAsBase64 = true
        };
        document.Save("1.html", saveOptions);

I have an svg in my html file and it looks good in the browser, but after the conversion I see my svg at the end of the document, but I want to see it in the correct position.

Below is the code I use

var document = new Document();

var builder = new DocumentBuilder(document);

builder.InsertHtml(File.ReadAllText("1.html"));

document.Save("out.docx", SaveFormat.Docx);
document.Save("1.pdf", SaveFormat.Pdf);

And I added zip with source html and result docx and pdf.example.zip (164.3 KB)

@AlexeyFilatov

Could you please ZIP and attach your input Word document (easy.docx) here for testing? We will investigate the issue and provide you more information on it.

@tahir.manzoor

Yes, sure
easy.zip (18.4 KB)

I convert it into html, add svg online on client side and want to convert it back into docx (and pdf).

@AlexeyFilatov

Unfortunately, we have not found the SVG in your Word document (easy.docx). Please check the attached image for detail.
easy.docx.png (112.7 KB)

Could you please share the document that contains the SVG?

@tahir.manzoor

Well, I have the following scenario:

  1. I have easy.docx
  2. I convert it to html
  3. The client adds svg to this html
  4. I am converting html with this svg to docx

And you can see, that svg is located at the end of the document, but if you open html in the browser, you can see svg in correct position.

Maybe, client has to add some spectific css style?

You can find html and result docx in zip in first message of this topic.

@AlexeyFilatov

The document you shared (1.html and 1.pdf) were created in evaluation mode of Aspose.Words. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document and SVG file.
  • Please attach the expected output Word or PDF file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

@tahir.manzoor

I have added a zip file with the necessary files.

And I want to repeat the script:
First of all, I’m creating an html from easy.docx . Then I send this html code to the client in the browser and the client can add some image using svg. The client sends me the html and svg result and I want the docx/pdf with this svg to be in the correct position.
I think I can convert html to docx and it will work correctly. But maybe a good way is to add svg to docx. But I do not know how I can do it.

AsposeTest.zip (308.4 KB)

@AlexeyFilatov

Please note that Aspose.Words mimics the behavior of MS Word. If you open the HTML in MS Word, the SVG is not imported into it.

However, we have logged this problem in our issue tracking system as WORDSNET-22913. You will be notified via this forum thread once there is any update available on it. We apologize for your inconvenience.

@AlexeyFilatov

We have closed this issue (WORDSNET-22913) as ‘Not a Bug’.

Aspose.Words supports only inline SVG images. In your case, HTML contains absolute positioned SVG and we cannot determine what text is behind the drawing.
Note that MS Word does not import SVG image.