Hi
I am trying to convert a doc containing (3 Column header) into html using Aspose.Word.java latest version. In html i am getting the header content as congested .
Here is my code.
import java.io.*;
import com.aspose.words.*;
class header
{
public static void main(String args[])
{
StringBuilder hString = new StringBuilder();
int size = 0;
try
{
Document aDoc = new Document("header.docx");
ByteArrayOutputStream bout = null;
NodeCollection nodes = aDoc.getChildNodes(NodeType.HEADER_FOOTER, true);
if (nodes.getCount()> 0)
{
for (int i = 0; i <nodes.getCount(); i++)
{
System.out.println("INSIDE");
com.aspose.words.Node node = nodes.get(i);
HeaderFooter headerFooter = (HeaderFooter) node;
Document tempDoc = new Document();
Body body = tempDoc.getFirstSection().getBody();
if (headerFooter.getStoryType() == StoryType.PRIMARY_HEADER)
{
NodeCollection hfChildren = headerFooter.getChildNodes();
for (int j = 0; j <hfChildren.getCount(); j++)
{
com.aspose.words.Node headerChild = hfChildren.get(j);
com.aspose.words.Node dstNode = tempDoc.importNode(headerChild, true,
ImportFormatMode.KEEP_SOURCE_FORMATTING);
size += dstNode.getText().length();
body.appendChild(dstNode);
}
if (body.getFirstChild() != null &&
body.getFirstChild().getText().trim().length() == 0)
{
body.getFirstChild().remove();
if (size> 1)
{
bout = new ByteArrayOutputStream();
tempDoc.save(bout, SaveFormat.HTML);
hString = new StringBuilder(new String(bout.toByteArray()));
}
}
}
System.out.println("HEADER CONTENT ::::" + hString);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
I have attached docx with this . Am i doing anything wrong ? Is there any other way to take header with styles? Please help me.
Regards,
Anbu.S