Issue with ShapeRenderer

Hi,

I’m using Aspose Words 14.3.

I’m trying to export all the shapes of a document using the ShapeRenderer.

One of the generated images is actually the same as another one (img0 and img1 in my test).

I attached the test document and the outputs.

Here is the code to reproduce:

License wordLi = new License();
wordLi.SetLicense(@"d:\Aspose.Total.Product.Family.lic");

ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);
imageSaveOptions.UseAntiAliasing = true;
imageSaveOptions.PaperColor = Color.Transparent;

Document d = new Document(@"d:\Tests\FloatingShapes.docx");
NodeCollection shapes = d.GetChildNodes(NodeType.Shape, true);
for (int i = 0; i < shapes.Count; i++)
{
    Shape shape = (Shape)shapes[i];
    ShapeRenderer renderer = shape.GetShapeRenderer();

    renderer.Save(@"d:\tests\img" + i + ".png", imageSaveOptions);
}

HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
htmlSaveOptions.UseAntiAliasing = true;
htmlSaveOptions.ExportXhtmlTransitional = true;

d.Save(@"d:\tests\html\out.html", htmlSaveOptions);

Also, the shape export is working correctly with the html export but the antialiasing isn’t.

Best regards,

Hi Calvo,

Thanks for your inquiry. I tested the scenario and have managed to reproduce the same problem on my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-9980. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hello,

Thank you for your reply.

Actually, I have 2 bugs:

  1. The wrong shape is exported.
  2. The shapes are not antialiased when the document is exported to html and the antialiasing save option is enabled.

Thank you very much.

Best regards,

Hi Calvo,

Thanks for your inquiry. We have logged WORDSNET-9980 to address the problem you mentioned in first point. Regarding your second point, please note that the SaveOptions.UseAntiAliasing property works only when the document is exported to the image formats such as Tiff, Png, Bmp, Jpeg. If we can help you with anything else, please feel free to ask.

Best regards,

Hello,

Thank you for your answer.

Thus, I’d like to request the feature to antialias the shapes while exporting documents to HTML/EPUB.

Thank you very much.

Best regards,

Hi Calvo,

Thanks for your request.

I have logged a new feature request in our issue tracking system. The ID of this issue is WORDSNET-9996. Our development team will further look into the details of this problem and we will keep you updated on the status of this issue. We apologize for your inconvenience.

Best regards,

Hi,

After further analysis and with Aspose Words 14.4, it turns out that it is not an issue with the ShapeRenderer.

The problem is actually that if different shapes are anchored to the same paragraph, Aspose Words “loads” only one shape for all of them.

Here’s a sample to reproduce with the attached documents:

int i = 0;
NodeCollection paragraphs = wordDocument.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph paragraph in paragraphs)
{
    foreach (Node node in paragraph.ChildNodes)
    {
        if (node.NodeType == NodeType.Shape)
        {
            Shape shape = (Shape)node;
            ShapeRenderer renderer = shape.GetShapeRenderer();
            renderer.Save(@"d:\tests\img" + i + ".png", imageSaveOptions);
            i++;
        }
    }
}

Please note that this issue with the shapes doesn’t happen if the document is exported to html.

Do you have a workaround for this issue?

Thank you.

Best regards,

Hi Calvo,

Thanks for your inquiry. I tested all your new documents with Aspose.Words for .NET 14.4.0 but was unable to observe any issue on my side. I suggest you please upgrade to the latest version, execute the following code on your end and see how it goes. I hope, this helps.

Document doc = new Document(MyDir + @"Formes flotantes vides.doc");
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);
imageSaveOptions.UseAntiAliasing = true;
imageSaveOptions.PaperColor = Color.Transparent;
int i = 0;
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph paragraph in paragraphs)
{
    foreach (Node node in paragraph.ChildNodes)
    {
        if (node.NodeType == NodeType.Shape)
        {
            Shape shape = (Shape)node;
            ShapeRenderer renderer = shape.GetShapeRenderer();
            renderer.Save(@"C:\temp\img" + i + ".png", imageSaveOptions);
            i++;
        }
    }
}

Best regards,

The issues you have found earlier (filed as WORDSNET-9996) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi Calvo,

Thanks for being patient.

Regarding WORDSNET-9980, it is to update you that our development team has completed the analysis of this issue and has come to a conclusion that this issue and the undesired behaviour you’re observing is actually not a bug in Aspose.Words. So, we will most likely close this issue as ‘Not a Bug’.

The problem occurs because there are both Shapes and DrawingMLs inside this document. Calling GetShapeRenderer() method internally calls UpdatePageLayout() method, during this operation by default Aspose.Words replaces all DrawingMLs with fallback Shapes. Our Shapes collection is live that is why the same Shape is rendered twice. To avoid this problem you can call UpdatePageLayout() method before rendering shapes. Please see the following code:

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
doc.UpdatePageLayout();
for (int i = 0; i < shapes.Count; i++)
{
    Shape shape = (Shape)shapes[i];
    ShapeRenderer renderer = shape.GetShapeRenderer();
    renderer.Save(@"C:\\Temp\\img" + i + ".png", imageSaveOptions);
}

I hope, this helps.

Best regards,