Hello,
I try to insert a document at a bookmark location of a main document. It’s ok but if the inserted document contains a section number which must follow existing one in main doc, it’s not ok. See example :
main doc :
- part one
- part two
2.1 part two-one
bookmark1
2.2 part two-two- part three
sub doc :
1.1 sub part
after insertion :
part one
part two
2.1 part two-one
1.1 sub part2.2 part two-two
- part three
but I want :
part one
part two
2.1 part two-one
2.2 sub part2.3 part two-two
- part three
My insertion code (copy from your forum) :
private void insertDocument(Node node, Document doc) throws Exception
{
CompositeNode parentNode = node.getParentNode();
while (true)
{
if (parentNode == null)
{
throw new Exception("Document cannot be inserted after the specified node.");
}
if (parentNode instanceof Story || parentNode instanceof Cell || parentNode instanceof Shape)
{
break;
}
node = parentNode;
parentNode = node.getParentNode();
}
int index = node.getParentNode().getChildNodes().indexOf(node);
Document dstDoc = node.getDocument();
Section insertedSection;
for (Node section : doc.getSections())
{
insertedSection = (Section) dstDoc.importNode(section, true, ImportFormatMode.KEEP_SOURCE_FORMATTING);
for (Node insertedNode : insertedSection.getBody().getChildNodes())
{
// Do not insert node if it is a last empty paragarph in the section.
if (insertedNode instanceof Paragraph && insertedNode == ((Section) section).getBody().getLastChild() && insertedNode.toTxt().equals(""))
{
break;
}
parentNode.getChildNodes().insert(++index, insertedNode.deepClone(true));
}
}
}
A bug ?