Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created June 12, 2025 06:07
Show Gist options
  • Save aspose-com-gists/a9219dd57b34f7eacd5ed306cdeba503 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/a9219dd57b34f7eacd5ed306cdeba503 to your computer and use it in GitHub Desktop.
Edit PDF Page Size in Java | change Paper Size in PDF
import com.aspose.pdf.*;
public class editPageSize {
public static void main(String[] args) {
// Load the PDF document
Document pdfDocument = new Document("sample_pdf.pdf");
// Resize all pages to A4
for (Page page : pdfDocument.getPages()) {
page.resize(PageSize.getA4());
}
// Save the modified document
pdfDocument.save("output_a4.pdf");
}
}
import com.aspose.pdf.*;
public class ResizeCustomPageSize {
public static void main(String[] args) {
// Load existing PDF
Document pdfDocument = new Document("sample_pdf.pdf");
// Define custom size (e.g., 500 x 700 points)
double customWidth = 500;
double customHeight = 700;
// Resize each page
for (Page page : pdfDocument.getPages()) {
page.setPageSize(customWidth, customHeight);
}
// Save the updated document
pdfDocument.save("output_custom_size.pdf");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment