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

Free Support Forum - aspose.com

Removing the hidden attribute from an image in a hidden paragraph

I have attached a word document with an inline image in a hidden paragraph. The hidden paragraph was created by highlighting the entire paragraph including the image and the end of paragraph marker then clicking the font hidden attribute.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Using the code below, I am trying to unhide the paragraph and all its content including the image. I am getting all the text and the end of paragraph marker un-hidden but not the image. I have looked at the Shape object but I can’t find anything that looks like the hidden attribute. How do I make the image visible using Aspose.Words?

var hidden = from Words.Run r in doc.GetChildNodes(Words.NodeType.Run, true, true)

where r.Font.Hidden == true

select r;

foreach(Words.Run r in hidden)

{

r.Font.Hidden = false;

r.ParentParagraph.ParagraphBreakFont.Hidden = false;

}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I see the problem, this occurs because there is no public access to the Font of shape. I created new issue #7510 in our defect database; we will consider a possibility of exposing this property.

Currently as a workaround, you can “reinsert” shape using DocumentBuilder. For example see the following code:

//Open document and create DocumentBuilder

Document doc = new Document(@"C:\Temp\hiddenimage.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

//Prepare query that will select all hidden run nodes

var hidden = from Run r in doc.GetChildNodes(NodeType.Run, true, true)

where r.Font.Hidden == true

select r;

//Prepare query that will select all inlime image shapes

var shapes = from Shape s in doc.GetChildNodes(NodeType.Shape, true)

where s.IsInline && s.HasImage

select s;

//loop through hiddent runs and reset Hidden property

foreach (Run r in hidden)

{

r.Font.Hidden = false;

r.ParentParagraph.ParagraphBreakFont.Hidden = false;

}

//Loop through inline images and reinsert them

foreach (Shape s in shapes)

{

//move document builder to the shape

builder.MoveTo(s);

builder.Font.Hidden = false;

//Reinssert image

Shape newImg = builder.InsertImage(s.ImageData.ImageBytes);

//Here you can export all properties of original Shape

newImg.Width = s.Width;

newImg.Height = s.Height;

//etc...

//Remove original shape

s.Remove();

}

//save output document

doc.Save(@"C:\Temp\out.doc");

Hope this helps.

Best regards.

Thanks, I will give it a try.

I just wanted to thank you for your help. Your products hit the mark and your technical support team is second to none. Every time I post a question I receive a response with 24 hours and usually it contains a work around or a link to a fix. I am very impressed with your company.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I tried your work around and it did the trick. Here is my final code:

Thanks again

Words.Document doc = new Words.Document(@"c:\temp\header.Doc");

Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

// select all hidden paragraphs in all primary page headers

var paragraphs = from Words.Section s in doc.Sections

from Words.Paragraph p in s.HeadersFooters[Words.HeaderFooterType.HeaderPrimary].Paragraphs

where p.ParagraphBreakFont.Hidden = true

select p;

// make hidden paragraphs and all child nodes visible

foreach(Words.Paragraph p in paragraphs)

{

// make paragraph break visible

p.ParagraphBreakFont.Hidden = true;

// make all runs inside the paragraph visible

foreach(Words.Run r in p.GetChildNodes(Words.NodeType.Run,true))

r.Font.Hidden = false;

// make images visible

foreach (Words.Drawing.Shape s in p.GetChildNodes(Words.NodeType.Shape, true))

{

// work around until font object exposed on shape object

// delete image and re-insert

if (s.HasImage)

{

builder.MoveTo(s);

builder.Font.Hidden = false;

Words.Drawing.Shape newImg = builder.InsertImage(s.ImageData.ImageBytes);

newImg.Width = s.Width;

newImg.Height = s.Height;

s.Remove();

}

}

}

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


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