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

Free Support Forum - aspose.com

Preserve A4 or Letter Paper Sizes during Word DOCX to PDF Conversion using Java

Hello Team,

we are doing a POC for generating PDF for word documents using Aspose.word.

PDF is getting generated successfully, but we are not seeing that as A4 size instead of that, it is generating as letter format.

what is the settings or config we need to use to render the PDF in A4 size or inherit same settings as word documents has.

Best Regards,
Sai

@Sai_Prasad_KR,

Aspose.Words should preserve the Paper Size during converting Word document to PDF format. Please ZIP and upload your input Word document and Aspose.Words generated PDF file showing the undesired behavior here for testing. We will then investigate the issue on our end and provide you more information.

@awais.hafeez, thanks for your quick response.

Current issues:

  1. Not generating the PDF in A4 format. Size for PDF in A4 - 210 x 297mm 8.3 x 11.7 inch
  2. Image in the document is getting shrink after PDF generation.

I am using below API to create the PDF.
document.save(“Filename”);
No additional options are used.

Attached source document and target PDF generated and pdf properties.

Aspose_PDF.zip (169.1 KB)

@Sai_Prasad_KR,

According to MS Word 2019, A4 paper size is actually equal to 8.27" x 11.69" inches (see A4 Paper Size.png (26.0 KB)). I have also converted your “Testing_Doc_Template.docx” file to PDF format manually by using the “Save As” command of MS Word 2019 and attached the PDF file here for your reference (see msw-2019.pdf (293.0 KB)). So, this is the expected behavior and Aspose.Words for Java mimics the behavior of MS Word in this case.

Please also provide a comparison screenshot highlighting (encircle) the problematic area(s) in Aspose.Words generated output PDF and attach it here for our reference. Also, you are using an old 20.8 version of Aspose.Words for Java on your end; we suggest you to please upgrade to the latest 21.5 version and provide 21.5 version generated PDF file here for further testing.

Also, you can customize the paper size by using the following Java code:

Document doc = new Document("C:\\Temp\\Aspose_PDF\\Testing_Doc_Template.docx");

for (Section section : doc.getSections()) {
    section.getPageSetup().setPageWidth(8.3 * 72); // 1 inch equals to 72 points
    section.getPageSetup().setPageHeight(11.7 * 72);
}

doc.save("C:\\Temp\\Aspose_PDF\\awjava-21.5.pdf");

Hi

Thanks Hafeez!

i have upgraded the Aspose.word to latest and image shrink problem has been resolved.

@Sai_Prasad_KR,

It is great that you were able to resolve this issue on your end. In case you have further inquiries or may need any help in future, please let us know by posting a new thread in Aspose.Words’ forum.