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.
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
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");
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.
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();
}
}
}