Can i insert something on a particular Page of a document


I would like to describe my problem here:

I want to insert a field in a particular page of a word document. So i am looking for a method in Aspose API where I give a page number to it and it allows me to insert a field code at the top of that page. Or is there anything in Aspose API to do this?

Looking forward to your response!


Thanks for your inquiry. Please note that MS Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document. Pages are created by Microsoft Word on the fly.
Aspose.Words uses our own Rendering Engine to layout documents into pages. Please check using the DocumentLayoutHelper sample from the offline samples pack. This sample demonstrates how to easily work with the layout elements of a document and access the pages, lines, spans etc.

Hope this helps you. Please let us know if you have any more queries.

Is DocumentLayoutHelper of part of Dot Net Samples code only? I could not find it in samples code of java.

Looking forward to your response.


Thanks for your inquiry. The DocumentLayoutHelper’s code for Java is not available at the moment. I have logged a new Task for this in our issue tracking system as WORDSJAVA-740. Your request has been linked to this Task. We will update you via this forum thread once the code sample of DocumentLayoutHelper is available. We apologize for your inconvenience.

Please try the following code snippet to achieve your requirements. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
int page = 0;
LayoutCollector lc = new LayoutCollector(doc);
ArrayList nodes = new ArrayList();
// Loop though Paragraphs
for (Paragraph para: (Iterable <Paragraph> ) doc.getChildNodes(NodeType.PARAGRAPH, true))
    // Add frist run node to ArrayList
    if (page != lc.getStartPageIndex(para))
        if (para.hasChildNodes())
            page = lc.getStartPageIndex(para);
DocumentBuilder builder = new DocumentBuilder(doc);
for (Run run: (Iterable <Run> ) nodes)
    builder.insertField("MERGEFIELD MyFieldName \\* MERGEFORMAT");
} + "out.docx");


Thanks a lot for the help … It doesn’t solve our problem completely. But it’s helpful.

I will wait till you bring up DocumentLayoutHelper for java.

Hi there,

Sure, we will update you via this forum thread once DocumentLayoutHelper for Java is available.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi there,

Thanks for being patient. Please try the attached DocumentLayoutHelper utility for Java. I hope, this helps.

The issues you have found earlier (filed as WORDSJAVA-740) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.