Hi,
We are having a problem while merging document which has bookmark created through Set Fields (Insert -->Field --> Bookmark) ,the book mark filed created normally is merging fine.I have already posted here regarding this ,that time aspose suggested to use REF field for the bookmark created using the Set field.The solution suggested was working fine but our Customer is saying that they can not change the template because they have lot of templates created like that and that was working in the desktop version of our Application. Recently only we have released browser version of our application and they are facing the problem there.
Please suggest any alternate solution for this and please clarify my question listed below and provide any help.
-
Could i able insert a REF field in the document immediately after the FieldEnd of corresponding bookmark using inserAfter(node,node) ?if so please help how to create a REF field node.
-
Could i delete the set field and replace replace the merge value there (please help on this if possible)
-
Could i able to move to the node and create a bookmark there and use the bookmark while merging without creating a temp document?
Hi Senthilv,
Thanks for your query. Please use the following code snippet for your requirement. Please modify the highlighted section of code as per your requirements. Let us know if you have any more queries.
- Could i able insert a REF field in the document immediately after the FieldEnd of corresponding bookmark using inserAfter(node,node) ? if so please help how to create a REF field node.
Document doc = new Document(MYDir + "BuildingPermit2006.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection nodes = doc.getChildNodes(NodeType.FIELD_START, true);
for (FieldStart start :(Iterable<FieldStart>)nodes)
{
if (start.getFieldType() == FieldType.FIELD_SET)
{
Node current = start;
while (current.getNodeType() != NodeType.FIELD_END)
{
current = current.getNextSibling();
}
builder.moveTo(current);
Paragraph para = builder.insertParagraph();
builder.moveTo(para);
builder.insertField("REF permitno");//You can change value as per your requirements
}
}
doc.save(MYDir + "AsposeOut-Java.docx");
-
Could i delete the set field and replace replace the merge value there (please help on this if possible)
-
Could i able to move to the node and create a bookmark there and use the bookmark while merging without creating a temp document?*
Document doc = new Document(MYDir + "BuildingPermit2006.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection nodes = doc.getChildNodes(NodeType.FIELD_START, true);
ArrayList nodeRemove = new ArrayList();
for (FieldStart start :(Iterable<FieldStart>)nodes)
{
if (start.getFieldType() == FieldType.FIELD_SET)
{
builder.moveTo(start);
builder.insertField("REF permitno");//You can change value as per your requirements
//Your 3rd question
//builder.startBookmark("MyBookmark");
//builder.write("Text inside a bookmark.");
//builder.endBookmark("MyBookmark");
for (Node node = start; node != null && node.getNodeType() != NodeType.FIELD_SEPARATOR && node.getNodeType() != NodeType.FIELD_END; node = node.nextPreOrder((Document)start.getDocument()))
{
nodeRemove.add(node);
}
}
}
for (Node node : (Iterable<Node>)nodeRemove)
{
node.remove();
}
doc.save(MYDir + "AsposeOut-Jave.docx");