We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to make inserted image displayed on the page's center

Use DocumentBuilder.insertImage() to insert a image into page.
How to make inserted image displayed on the page’s center?


Hi there,

Thanks for the inquiry. I will suggest you to visit documentation here. Please follow up the code snippet below.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// The best place for the watermark image is in the header or footer so it is shown on every page.


// Insert a floating picture.

BufferedImage image = ImageIO.read(new File(getMyDir() + "Watermark.png"));

Shape shape = builder.insertImage(image);





// Calculate image left and top position so it appears in the centre of the page.

shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2);

shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2);

doc.save(getMyDir() + "DocumentBuilder.InsertWatermark Out.doc");

I hope this will help.