Problem with html documents generated after changing library Aspose.Words.jdk16.jar 10.0.1

Hi,

I’ve downloaded a new revision for the library Aspose.Words.jdk16.jar (now i’ve got the 10.0.1 revision).
Now I’ve got some problem when I save a document into HTML format.

I’ve got a docx file, with special tag called ‘pastille’ using a font called ‘Numero’ (see texte_annexes_pastillé.docx joined to this topic).
I change some value in these tags with a java method in order to transform this font into a simple text like ‘(1)’ and then I save the document in html format. (see the 2 html files joined to this topic).

I use my own DocumentVisitor wich just change a Text into a Run object:

run.setText("(" + countPastille + ")");
private static void remplacerPastillage(Document doc)
{
    Visitor myConverter = new Visitor();
    try
    {
        doc.accept(myConverter);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

private void remplacerPastille(Paragraph para, Border leftBorder)
{
    Shape shape = (Shape) para.getChild(NodeType.SHAPE, 0, true);
    leftBorder.clearFormatting();
    if (shape != null)
    {
        try
        {
            Paragraph sousParagraph = (Paragraph) para.getChild(NodeType.PARAGRAPH, 0, true);
            if (sousParagraph != null)
            {
                sousParagraph.getParagraphFormat().setStyleName("StylePastille");
            }
            countPastille++;
            Run run = (Run) para.getChild(NodeType.RUN, 0, true);
            if (run != null)
            {
                run.setText("(" + countPastille + ")");
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}

code OK

OutputStream os = new java.io.FileOutputStream(temporayFile);
doc.getSaveOptions().setHtmlExportImagesFolder("/" + imagesDirectory);
doc.getSaveOptions().setHtmlExportHeadersFooters(false);
doc.getSaveOptions().setHtmlExportPageSetup(false);
doc.getSaveOptions().setHtmlExportAllowNegativeLeftIndent(true);
doc.getSaveOptions().setHtmlExportDocumentProperties(true);
doc.getSaveOptions().setHtmlExportTextInputFormFieldAsText(true);
doc.getSaveOptions().setHtmlExportCssStyleSheetType(CssStyleSheetType.EMBEDDED);
doc.save(os, SaveFormat.HTML);

Result
(1)
Ligne

code NOK

HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setImagesFolder("/" + imagesDirectory);
saveOptions.setExportHeadersFootersMode(ExportHeadersFootersMode.NONE);
saveOptions.setExportPageSetup(true);
saveOptions.setAllowNegativeLeftIndent(true);
saveOptions.setExportDocumentProperties(true);
saveOptions.setExportTextInputFormFieldAsText(true);
saveOptions.setCssStyleSheetType(CssStyleSheetType.EMBEDDED);
doc.save(temporayFile, saveOptions);

Result
Ligne

Hi
Thanks for your request. I tried converting your document to HTML using the latest version of Aspose.Words for Java (10.2.0) and as I can see, the output looks closer to the original HTML. Please see the attached screenshot.
If it is not what you would like to get, please provide us full code you are using for converting your document to HTML. We will check it and provide you more information.
Best regards,

Hi,

I don’t want to have a html result which looks exactly like the initial document.
But I need to change each element with “Numero” Font into a String like “(1)”, “(2)”, etc…

I’ve joined a file TestService.java so that you can run your test with 2 different versions of Aspose.Words.jdk16.jar.
[2675 Ko] v-??? (I don’t know what release is the older one)
[4475 Ko] v-10.0.1

You can check it, it will be more efficient…
NB : you already have the initial document docx in this topic.

Thanks

Hi
Thanks for your request. Please try to modify your code as shown below:

private void remplacerPastille(Paragraph para, Border leftBorder)
{
    Shape shape = (Shape) para.getChild(NodeType.SHAPE, 0, true);
    leftBorder.clearFormatting();
    if (shape != null)
    {
        try
        {
            Paragraph sousParagraph = (Paragraph) para.getChild(NodeType.PARAGRAPH, 0, true);
            if (sousParagraph != null)
            {
                sousParagraph.getParagraphFormat().setStyleName("StylePastille");
            }
            countPastille++;
            Run run = (Run) para.getChild(NodeType.RUN, 0, true);
            if (run != null)
            {
                run.setText("(" + countPastille + ") ");
            }
            para.prependChild(run);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}

Hope this helps.
Best regards,

Ok, I’ve tried with this solution, we almost got it but the vertical alignment is not correct.
The indentation is no more available, if you compare with the original word document…

The result is like this :
Article1
(1)Ligne
(2)Ligne
What I want is like this :
Article 1
(1) Ligne
(2) Ligne

So I think that we should not inject the “Run” object into this Paragraph Node, but I don’t know where it should be inserted and I cannot see the real name of the objects in the debugger …

Thanks for your response.

Hi
Thanks for your request. The problem occurs because the way how Aspose.Words handles content inside Shape nodes was changed. In earlier versions Aspose.Words extracts content from the shape and insert at the place of the shape when you convert to HTML. Currently, Aspose.Words is supposed to render the Shape as an image. That is why you see such significant difference.
If you have a control over the document creation process, you can easily workaround the problem by avoiding using TextBox Shapes to layout content in your document.
Best regards,