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

Free Support Forum - aspose.com

Rendered Document with headerfooters

After rendering MS Word document that contains headerfooter with child nodes, as pararagraphs and runs, the LayoutEntity objects, as Spans and Lines that represent paragraph, dont have parent node. Is it a bug?

I take yours code on link:

and use the method GetLayoutEntitiesOfNode.

public LayoutCollection GetLayoutEntitiesOfNode(Node node)

{

if (!mLayoutCollector.Document.Equals(node.Document))

throw new ArgumentException("Node does not belong to the same document which was rendered.");

if (node.NodeType == NodeType.Document)

return new LayoutCollection(mChildEntities);

List entities = new List();

// Retrieve all entities from the layout document (inversion of LayoutEntityType.None).

foreach (LayoutEntity entity in GetChildEntities(~LayoutEntityType.None, true))

{

if (entity.ParentNode == node)

entities.Add(entity);

// There is no table entity in rendered output so manually check if rows belong to a table node.

if (entity.Type == LayoutEntityType.Row)

{

RenderedRow row = (RenderedRow)entity;

if (row.Table == node)

@Vlad94

Thanks for your inquiry. This is not a bug. You can use LayoutEnumerator.MoveParent method to move to the parent entity. We suggest you please read the members of LayoutEnumerator class.

Please also try EnumerateLayoutElements code example. Please get the code of “EnumerateLayoutElements” in Aspose.Words for .NET examples repository at GitHub. Hope this helps you.

If you face any issue, please share some detail about your requirements. We will then provide you more information about your query.

Thank you for fast reply. The MoveParent method move entity to parent entity. But I need to know that the entity have parent node, as paragraph or another node of document. In screenshot I show that the entity in rendered document, that have parent entity Headerfooter, does not have parent node. For examle, I have the document that contains in first section a headerfooter and a body. The headerfooter contains the paragraph. The paragraph contains some runs. After rendering i see that the rendered document have child entities: headerfooter entity, line entity and span entity, that have parent(parent entity) field - headerooter entity. But the field “parent node” of span and line is null. If we looks the “Body” element that also contains paragraph and child nodes(runs) of this paragraph and look this element in rendered document we can to see that lines(that represent paragraph in Aspose document) and spans(that represent runs in paragraph) also have field “Parent Node”, but this field does not null. This field have reference to original paragraph in Aspose document. So I asked you. Why the child entities of headerfooters in rendered document dont have link to parent node in original Aspose document.

http://dropmefiles.com/thGJd

This link have the .rar file that have a sample project where yo can see that child nodes entities of document that is in the headfooter dont have reference to parent node.

Thank you.

Hi there,

Thanks for your inquiry. RenderedDocument utility provides an API wrapper for the LayoutEnumerator class to access the page layout entities of a document. You need to modify this utility according to your requirements.

If you want to get the layout entities of header/footer of document, please use following code example.

Could you please share some more detail about your query what information of document you want to get using Aspose.Words.Layout API? We will then provide you more information about your query.

Document doc = new Document(MyDir + "target3.docx");
// This creates an enumerator which is used to "walk" the elements of a rendered document.
LayoutEnumerator it = new LayoutEnumerator(doc);
// This sample uses the enumerator to write information about each layout element to the console.
LayoutInfoWriter.Run(it);
// This sample adds a border around each layout element and saves each page as a JPEG image to the data directory.
OutlineLayoutEntitiesRenderer.Run(doc, it, MyDir);

Hello,

Thank you for your reply. I tried to see how the document is rendered, but when I tried to call the GetEntity method from the LayoutCollector object, it returns null. The node that I sent was the headerfooter node. That’s why I think it’s a problem why HeaderFooter Entity objects and child objects do not have a parent node. Help me to solve this problem. In the screenshot, I’ll show you the information I’m taking on time, debugging the program.

Thanks in advance.

Best regards, Vlad.

Hi Vlad,

Thanks for your inquiry. This LayoutCollector.GetEntity doesn’t work for Run, CellRow or Table nodes, and nodes within header/footer. This is the reason you are getting null value. Please check the detail of this method from here:

LayoutCollector.GetEntity method

Hello!

Thanks for the quick response. Your answer was helpful. Can I ask you a lot of questions? I create the document by importing the nodes. When I was importing the nodes, I was saving a reference to these nodes in the array. After that, I rendered the document using RenderedDocument class, and when the document was rendered, the nodes in the array lost references in the fields “NextSibling”, “PreviousSibling” and “ParentNode”. Why did this happen?

Sincerely, Vlad.

Hi Vlad,

Thanks for your inquiry.

Vlad94:

I create the document by importing the nodes. When I was importing the nodes, I was saving a reference to these nodes in the array. After that, I rendered the document using RenderedDocument class, and when the document was rendered, the nodes in the array lost references in the fields “NextSibling”, “PreviousSibling” and “ParentNode”. Why did this happen?

Could you please share following resources here for testing?

  • Your input Word document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Please do not share the code of RenderedDocument and remove the references from your application.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

Vlad94:

Can I ask you a lot of questions?

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.