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

Free Support Forum - aspose.com

Page margins are changed after Word to PDF conversion using Java


I am trying to create Word and PDF file by following code:

    public static void main(String[] args) throws Exception
// Create source
Document sourceDocument = new Document();
DocumentBuilder builder = new DocumentBuilder( sourceDocument );
    builder.getPageSetup().setLeftMargin( 250 );
    builder.getPageSetup().setRightMargin( 250 );
    builder.getCellFormat().setWidth( 500 );
    builder.write("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");

    sourceDocument.save( "C:\\Data\\tmp\\1.docx", SaveFormat.DOCX );
    sourceDocument.save( "C:\\Data\\tmp\\1.pdf", SaveFormat.PDF );

And get files, which looks different (see attachment). It seems, that page margins doesn’t works correctly for PDF. How I can fix it?

I am using version of Aspose.Words

Hi Nikolay,

Thanks for your query. Please use the following line of code before saving the pdf file. Let us know, If you have any more queries.


Thank you, it works!