Set PDF Dimensions and Margins

Im working with DOM for PDFs and I am inquiring how to be able to set the page size to A4 landscape and have margins all around at 1/4 inches? Note I am working with variable-page PDFs and not static-page PDFs.

Hi Junmil,


Thanks for your inquriy. You can set page dimensions and margins while creating the page as following. Hopefully it will help you to accomplish the task. However if you find any issue then please share your sample code here, so we will look into it and guide you accordingly.

com.aspose.pdf.Document doc = new
com.aspose.pdf.Document();<o:p></o:p>

// Set the page size as A4 (8.3 in x 11.7 in). In Aspose.Pdf, 1 inch = 72 points

// so A4 landscape dimensions in points is (842.4, 597.6).

Page page= doc.getPages().add();

page.getPageInfo().setHeight(597.6);

page.getPageInfo().setWidth(842.4);

MarginInfo marginInfo = new MarginInfo();

marginInfo.setLeft(18);

marginInfo.setRight(18);

marginInfo.setTop(18);

marginInfo.setBottom(18);

page.getPageInfo().setMargin(marginInfo);


Please feel free to contact us for any further assistance.


Best Regards,