Using InsertHtml MEthod

Hi,

I want to display the image with page number (Table format) using insert method into Document Footer Section for java.

So, Please share the possible ways /Code Snippet to implement the expected changes into word document.

footer_design.JPG (10.5 KB)

Thanks & Regards,
Shyamala

@Shyamu

You can use the following code example to create the table with image and page number field.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);

builder.startTable();
Cell cell = builder.insertCell();
cell.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(80));
builder.insertImage(MyDir + "image.png")

// Build the second cell
builder.insertCell();
builder.write("Page : ");
builder.insertField(FieldType.FIELD_PAGE, true);

// Call the following method to end the row and start a new row.
builder.endRow();

builder.endTable();
doc.save(MyDir + "19.9.docx");

If you want to use HTML in the footer of document, we suggest you following solution.

  • Move the cursor to the footer of document using DocumentBuilder.moveToHeaderFooter method.
  • Insert the HTML using DocumentBuilder.InsertHtml.
  • Get the table from the footer of document using CompositeNode.GetChild method.
  • Move the cursor to the second cell table and insert the Page field.

Hope this helps you.

Thanks Tahir !!

Suggested solutions helps me a lot and implemented the expected footer table