Free Support Forum - aspose.com

How to get the header and footer as a HTML

Hi,
Is there any method in Aspose to get the header and footer as a html string?

for (int i = 0; i < section.getChildNodes().getCount(); i++)
{
Node node = section.getChildNodes().get(i);

// Every node has the NodeType property.
switch (node.getNodeType())
{
case NodeType.BODY:
{
// If the node type is Body, we can cast the node to the Body class.
Body body = (Body)node;

// Write the content of the main story of the section to the console.
System.out.println("*** Body ");
System.out.println(body.getText());
break;
}
case NodeType.HEADER_FOOTER:
{
// If the node type is HeaderFooter, we can cast the node to the HeaderFooter class.
HeaderFooter headerFooter = (HeaderFooter)node;

// Write the content of the header footer to the console.
System.out.println("
HeaderFooter ***");
System.out.println(headerFooter.getHeaderFooterType());
System.out.println(headerFooter.getText());
break;
}

I am using the above code for to get the header and footer node.
I can get only the text by headerFooter.getText().
why don’t you give the method like headerFooter.getHtml() or headerFooter.toHtml().

I need to get the header and footer as a html string either from the doc or from the converted html.
In the first case i can only get the header as a TEXT not as a HTML by aspose methods.
In the second case header and footer are not surrounded by any container and also there is no unique pattern for to identify the header and footer.

In openoffice case in the html they give the header and footer surrounded by DIV container and also give some unique pattern like
. In that case i can easily identify the header and footer from the html and get the same from the html.

Is there any method to get the innerhtml of the given node?

Waiting for your reply,

Thanks,
chandrasekar.P


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

Thanks for your request. I think that you can create temporary document and insert header there. For example see the following code:

//Open source document

Document doc = new Document("in.doc");

//Create temporary document

Document tempDoc = new Document();

//Get child nodes from header

NodeCollection headerChildren = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getChildNodes();

//Loop through all nodes inside header

for (int i = 0; i < headerChildren.getCount(); i++)

{

//Import node

Node dstNode = tempDoc.importNode(headerChildren.get(i), true, ImportFormatMode.KEEP_SOURCE_FORMATTING);

tempDoc.getFirstSection().getBody().appendChild(dstNode);

}

//Save temporary document in HTML fromat

tempDoc.save("out.html", SaveFormat.HTML);

Hope this helps.

Best regards.