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

Free Support Forum - aspose.com

Change PDFSize to Letter

I am trying to change PDF size of every page to LETTER and by using the following code, i am able to achieve it, but there are some issues. I need a proper way to do it. Please help me out as this is very urgent.

Approach 1

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(sourceFile);
PageCollection pageCollection = pdfDocument.getPages();
for(int i=1;i<=pageCollection.size();i++){
Page pdfPage = pageCollection.get_Item(i);

Using above approach is cutting the top content part of the final pdf which is not acceptable.

Approach 2

PdfPageEditor pEdit = new PdfPageEditor();
int total_pages = pEdit.getPages();
for(int i=1; i <=total_pages; i++)
pEdit.setProcessPages(new int[] { i });
float zoomvalue = 0;
if (pEdit.getPageSize(i).getHeight() > pEdit.getPageSize(i).getWidth())
zoomvalue = com.aspose.pdf.PageSize.getPageLetter().getHeight() / pEdit.getPageSize(i).getHeight();
zoomvalue = com.aspose.pdf.PageSize.getPageLetter().getWidth() / pEdit.getPageSize(i).getWidth();


Above approach is working fine and able to get the proper pdf but the final pdf size is very huge and again this is not acceptable. I have a 2MB file using this code it is turning into 10.5MB

Please suggest a best approach so that i do not loose the content and maintain the size. I need to change all the pages to LETTER

Hi Gowtham,

Thanks for contacting support.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}

I will appreciate if you please share your sample PDF file. It will help us to replicate the issue at our end and address it accordingly.

Moreover, please use following code snippet to test with your PDF file.


Document pdfDocument = new Document(dataDir + "pdf-sample.pdf");
PdfFileEditor pfe = new PdfFileEditor();
//Specify Parameter to be used for resizing
PdfFileEditor.ContentsResizeParameters parameters = PdfFileEditor.ContentsResizeParameters.pageResize(
com.aspose.pdf.PageSize.getA2().getHeight(), com.aspose.pdf.PageSize.getA2().getWidth());

for (int i = 1; i < pdfDocument.getPages().size() + 1; i++) {
parameters.setLeftMargin(PdfFileEditor.ContentsResizeValue.units(0)); parameters.setRightMargin(PdfFileEditor.ContentsResizeValue.units(0));
pfe.resizeContents(pdfDocument, new int[]{i}, parameters);


pdfDocument.save(dataDir + "resized12.pdf");

If you still face any issues or need further assistance, please feel free to contact us.

We are sorry for the inconvenience.

Best Regards,