Learn how to Edit PDF Page Size in Java
Created
June 12, 2025 06:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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