How to insert Shape on each page of an Aspose.Words document?

I have an Aspose.Words document. I would like to insert a TextBox Shape on each page of my document.

This is my document:

// Aspose.Words document
Document document = new Document();

// The DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(document);

builder.insertHtml("Here, there is a big String with a lot of HTML.");

This is how I do it for the first page:

Shape textBox = new Shape(document, ShapeType.TEXT_BOX);
textBox.setWrapType(WrapType.SQUARE);
// Shape position
textBox.setDistanceTop(0);
textBox.setDistanceLeft(42);
// Shape dimensions
textBox.setWidth(200);
textBox.setHeight(20);

// ... other options useless here.

// Paragraph, content of the Shape
Paragraph paragraph = new Paragraph(document);
Run run = new Run(document);
run.setText("Here some text.");
paragraph.appendChild(run);

textBox.appendChild(paragraph);

// Now I insert my Shape on the first page.
builder.moveToDocumentStart();
builder.insertNode(textBox);

This is working great for the first page.

I also know that I can get the number of pages doing:

document.getPageCount();

However I do not know how to go through all the pages.

Any suggestions?

Finally, I found a solution.


First of all I use the code provided by Adam Skelton available here, this is not in Java but I manage to adapt it.

Then, I tried to directly save the document as a PDF but it is not working…
The PDF is saved correctly but there is only the HTML inserted, and not the shapes.

However, if I first save the document as a DOC file and the load it and save it as a PDF file, it works great !

Any explanations ?

Hi
Florian,


Thanks for your query. Please use the latest version of Aspose.Words for Java. If you still face problem, please share your code and documents for investigation purposes.