Changing paper size does not resize shapes relative to page size

Hi,

In the code below, I am changing a paper size of a document that contains a shape which size is set relative to page size. After the paper size is changed for the document, the shape size remains unchanged. Only after the document is saved, the shape’s size changes.

See the the following piece of code (I have tried to attach the document ShapeSizeChange1.docx as well, but it’s not allowed anymore):

Document doc = new Document("ShapeSizeChange1.docx");
			
System.out.println( "Page size before: " + doc.getFirstSection().getPageSetup().getPaperSize());
Shape shape = (Shape) doc.getFirstSection().getBody().getChild(NodeType.SHAPE, 0, true);
System.out.println( "Shape width before: " + shape.getWidth());    
System.out.println( "Shape height before: " + shape.getHeight()); 
			
doc.getFirstSection().getPageSetup().setPaperSize( PaperSize.A4);
			
System.out.println( "----" );
System.out.println( "Page size after change : " + doc.getFirstSection().getPageSetup().getPaperSize());
System.out.println( "Shape width after change: " + shape.getWidth());    
System.out.println( "Shape height after change: " + shape.getHeight());  
		    
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions( SaveFormat.DOCX );
saveOptions.setCompliance( OoxmlCompliance.ISO_29500_2008_TRANSITIONAL );
doc.save( "saved.docx", saveOptions );
			
System.out.println( "----" );
System.out.println( "Page size after save : " + doc.getFirstSection().getPageSetup().getPaperSize());
System.out.println( "Shape width after save: " + shape.getWidth());    
System.out.println( "Shape height after save: " + shape.getHeight());  

ShapeSizeChange1.docx contains one section with a shape node. The size of the shape node is setup relative to the page size. See the picture.ShapeSizeSetup.png (44.4 KB)

Please let me know if this can be fixed anytime soon.
Thanks,

Natasa

@nfecanin

Thanks for your inquiry. Please call Document.UpdatePageLayout method before getting the shape’s size. Hope this helps you.

Thank you very much, this helped!

@nfecanin

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