Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java code to resize existing PDF size to A3 Size

What I have tried:

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.PdfPageSize;
import com.spire.pdf.graphics.*;
import java.awt.geom.Point2D;
public class ResetToStandardPageSize {
public static void main(String []args){
//Create a new PDF document
PdfDocument newPdf = new PdfDocument();
//Set page size as A1
newPdf.getPageSettings().setSize(PdfPageSize.A1);
//Remove page margins
newPdf.getPageSettings().setMargins(new PdfMargins(0));
//Load the sample PDF document
PdfDocument pdf = new PdfDocument("Sample.pdf");
//Iterate through the pages in the sample PDF
for(int i = 0; i< pdf.getPages().getCount(); i++)
{
//Add pages to the new PDF
PdfPageBase newPage = newPdf.getPages().add();
//Set text layout as 1 page, if not set the content will not scale to fit page size
PdfTextLayout layout = new PdfTextLayout();
layout.setLayout(PdfLayoutType.One_Page);
//Create templates for the pages in sample PDF and draw templates to the pages of the new PDF
pdf.getPages().get(i).createTemplate().draw(newPage, new Point2D.Float(0,0), layout);
}
//Save the result document
newPdf.saveToFile("ChangePageSizeToA1.pdf");
}
}
Posted
Comments
Richard Deeming 3-Nov-22 11:23am    
You've forgotten to ask a question.
Richard MacCutchan 3-Nov-22 11:36am    
Why are you using A1 if you want it to be A3?
OriginalGriff 3-Nov-22 11:40am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900