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