Image does not fill page in Landscape mode


Hi Aspose team,

I am trying to insert an image into a page in landscape mode but no matter how the image is resized, I can’t seem to get it to fill the page. My speculation is that the image’s max size seems to be bounded for portrait mode. Even when I set the proper height and width to fill the page in landscape mode, it always reduces the maximum width of the image to be the max width for a page in portrait mode.

Note that to resize my image to fit the page, I have also tried the code fragment from this topic. I have a header and a footer on this page but they were taken into consideration when calculating the free space available.

Version of aspose words that I’ve tried this on - 16.4, 19.5



Please use the latest version of Aspose.Words for Java i.e. 19.6 and check if the following code example works for you?


Hi Awais,

Thanks for your quick reply. I’ve tried what you suggested and that did not work for me either. A few more notes about my scenario - the image that I am inserting is an SVG image converted to a byte array. I turned that byte array into a file to try the code fragment that you recommended and it made the image smaller.

We’re a licensed user and need this for our product’s next release, please let me know if there’s another forum that I should post this in.




To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Your SVG (image) file
  • Aspose.Words 19.6 generated output document showing the undesired behavior
  • Your expected document showing the correct output. You can create expected document by using MS Word.
  • Please also create a simplified standalone Java application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.


Hi Awais,

I’ve attached a zip containing everything you’ve enlisted other than the stand-alone Java application. The same code fragment was used as the one suggested in this topic. In the zip file, you’ll see the SVG image, with the expected and unexpected word documents.

ThanksFor Aspose (555.4 KB)



Please try using the following code to fix the image in ‘Image not resized.docx’:

Document doc = new Document("E:\\temp\\For Aspose team\\Image not resized.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

Shape img = (Shape) doc.getFirstSection().getBody().getChildNodes(NodeType.SHAPE, true).get(1);
Shape newImg = builder.insertImage("E:\\temp\\For Aspose team\\image.svg");

img.remove();"E:\\temp\\For Aspose team\\awjava-19.6.docx");

Hope, this helps.


Hi Awais,

The solution we are looking for is having the image resized correctly during document creation.

The SVG image that we generate is done dynamically, and is not saved to a file. A solution like this would require us to save it first to a temp file as well. There are also cases where there will be multiple diagrams in our document and it is not guaranteed on which section or page the image will be placed. I’ve attached an example of that as well.


Multiple Diagrams (434.6 KB)



Can you please also elaborate on what pages inside ‘Multiple Diagrams Example.docx’ document the images are appearing incorrectly?


Hi Awais,

The pages with the image in landscape mode (as per the thread title) are supposed to fill the page, so there are no images appearing correctly - pages 1 and 22.



I think, you do not need to manually set the Width/Height of image. Just use the insertImage method. If the image is bigger, then Aspose.Words will auto-resize the image to fit in the page width. Here is sample code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup ps = doc.getFirstSection().getPageSetup();

Shape newImg = builder.insertImage("E:\\temp\\For Aspose team\\image.svg");"E:\\temp\\awjava-19.6.docx");

Hope, this helps.


Hi Awais,

This solution works for me, you can close this ticket.

Thanks for the help!