Problems with positioning fields in Word template

Problems with positioning fields in Word template.

I have a Word template (.dotx). In this template I have in the header of the second page a default barcode (in a table), which I want to replace with the real barcode I generate with Aspose Barcode for this item. How can I replace this barcode?

I also want to insert a new table on the second page, on a specific place on the page. I succeeded to insert the table after a new section, but I want to place it after a specific (Merge)Field or something like that. How can I position the cursor? I cann't position the cursor with MoveToField.

I will sent the java class, the input template and the created document with this message.

Hi Ernst,

Thanks for your inquiry.
Ernst:

I have a Word template (.dotx). In this template I have in the header of the second page a default barcode (in a table), which I want to replace with the real barcode I generate with Aspose Barcode for this item. How can I replace this barcode?

Please try run the following code snippet, this replaces your sample BarCode image with another Image.
Document doc = new Document("C:\\Temp\\TestFormulier.dotx");
DocumentBuilder builder = new DocumentBuilder(doc);

DrawingML dml = (DrawingML)doc.getFirstSection().getHeadersFooters()
.getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY)
.getChildNodes(NodeType.DRAWING_ML, true).get(0);

Paragraph refPara = (Paragraph)dml.getParentParagraph();

dml.remove();

builder.moveTo(refPara);
builder.insertImage(“C:\Temp\NewBarCode.png”);

doc.save(“C:\Temp\out.docx”);

Ernst:

I also want to insert a new table on the second page, on a specific place on the page. I succeeded to insert the table after a new section, but I want to place it after a specific (Merge)Field or something like that. How can I position the cursor? I cann’t position the cursor with MoveToField.

I believe, you can achieve this after reading the article suggested below:

Please let me know if I can be of any further assistance.

Best regards,

Thanks for your answer.

Theproblem is solved and it works.