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

Free Support Forum - aspose.com

Margins not working for top and bottom

I’m trying to set equal margins in my document for top, bottom, left and right.
When I’m applying margin by creating blank document at that its working fine. But its not working when I’m trying to apply these settings in existing document.

Following is the code snippet I’m using to apply the settings.

public class ConvertBetweenMeasurementUnits {
	public static void main(String[] args) throws Exception {
		// Open the document.
		Document doc = new Document("/home/user/Downloads/existing.docx");
		DocumentBuilder builder = new DocumentBuilder(doc);
		PageSetup pageSetup = builder.getPageSetup();
		pageSetup.setTopMargin(ConvertUtil.inchToPoint(0.984));
		pageSetup.setBottomMargin(ConvertUtil.inchToPoint(0.984));
		pageSetup.setLeftMargin(ConvertUtil.inchToPoint(0.984));
		pageSetup.setRightMargin(ConvertUtil.inchToPoint(0.984));
		pageSetup.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
		pageSetup.setFooterDistance(ConvertUtil.inchToPoint(0.2));
		doc.save("/home/user/Desktop/output.doc");
	}
}

Please find attached related files.zip (26.1 KB)
for your reference and let me know if you have any solution for this issue.

Thanks

@nobilex,
Unfortunately, we were unable to detect the issue on our side. As I can see, the margins in your output document are set to the desired values (0.984 inches from each side).
Could you please share a screenshot, that shows the unexpected behavior? We will investigate the issue and provide you information on it.

Thanks @sergey.lobanov for the quick response.

Yes, I’ve check the same. I was checking in LibreOffice (Ubuntu), where its showing incorrect but In Windows, its good as expected.

Thanks