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

Free Support Forum - aspose.com

Can I make a Shape invisible

Hi,

I’m currently using Aspose.Words 9.7.0 and looking for a way to (temporary) hide a shape. I did some searching and I found that the Aspose.Cells Shape object has an IsHidden property. However, I’m unable to find the Aspose.Words equivalent. Does is exist?

Hi

Thanks for your request. You can achieve using code like the following:

// Open document.

Document doc = new Document(@"Test001\in.doc");

// Get collection of shapes.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

foreach (Shape shape in shapes)

{

// get shape make it hidden.

shape.Font.Hidden = true;

}

// Save output.

doc.Save(@"Test001\out.doc");

Best regards,

Hi,

Thank you for your response, but I’m unable to get it working. I’ve attached the test document and this is the code I’m using:

Document document = new Document(@“D:\Temp\TestDocument.doc”);

NodeCollection shapes = document.GetChildNodes(NodeType.Shape, true);

foreach (Shape shape in shapes)
{
Console.WriteLine(shape.Name + " " + shape.Font.Hidden);
shape.Font.Hidden = true;
Console.WriteLine(shape.Name + " " + shape.Font.Hidden);
}

document.Save(@“D:\Temp\Result.doc”, SaveFormat.Doc);

The document contain several floating images (body, header, footer) and also an inline shape in the body. None of the images are hidden in the result document.

Hello,

Thank you for additional information.
Unfortunately, I could not reproduce the problem on my side. I'm using exactly the same code as you, but in my output document all the pictures are invisible. But the picture itself in the document are present, this can be easily ascertained using Document Explorer (C:\Program Files\Aspose\Aspose.Words for. NET\Demos\CSharp\DocumentExplorer)
Please tell me what version of MS Office you are using?

Hi,

That’s strange. I’m using Office 2010 on my dev machine. I also tested it by opening the created document in Office 2003 and Office 2007 and it gives the same result. Saving the document as docx doesn’t seem to help also. I’ve attached the created document to this post.

Thank you for additional information. Tell me how you would like to document looks like after the image will be "invisible". I mean, they would have simply disappeared from the document and moved the text? Or do they remain in place, but were, for example, white?

If the second suit, you can change the brightness of images.

shape.ImageData.Brightness = 1;

to return to the previous brightness, set it equal to 0.5.

Still describe how you see the disappearance of images. I will try to help.

Hi

Thanks for your request. You do see the hidden images because “Display hidden text” option is enabled in MS Word. Disable this option and you will not see the hidden content. Please see the attached screenshot.

Best regards,

In Word itself it's possible to make a (floating) shape invisible by code:

ActiveDocument.Sections.First.Headers(wdHeaderFooterPrimary).Shapes("ShapeHeader").Visible = False

Hidden shapes still exist in the document (so they can be turned on again at a later time)
I want to achieve this same behavior with Aspose.Words.

When I set the brightness the 0 the image is indeed invisible. However, it still takes it's place in the document (it's selectable)


Hi

Thank you for additional information. Unfortunately, there is no public API to set this property using Aspose.Words. I logged your request in our defect database. We will let you know once this property is available in public API.

Best regards,

Hello,

It’s been a while since I’ve asked this question, but it it still not possible with the current version?

Regards,
Alexander

@ademan

Thanks for your inquiry. I am afraid the requested feature is still not implemented due to other priority tasks. Moreover, the demand of this feature is very low so its implementation is not planned yet. However, we will notify you as soon as we made some significant progress towards its implementation.

Thanks for your patience and cooperation.