diff --git a/en/java/advanced-operations/working-with-documents/formatting-pdf-document/_index.md b/en/java/advanced-operations/working-with-documents/formatting-pdf-document/_index.md index fcc92da7f..d4b8b13e8 100644 --- a/en/java/advanced-operations/working-with-documents/formatting-pdf-document/_index.md +++ b/en/java/advanced-operations/working-with-documents/formatting-pdf-document/_index.md @@ -274,63 +274,6 @@ public static void GetAllFontsFromPDFDocument() { } ``` - -### Get Warnings for Font Substitution - -Aspose.PDF for Java provides methods to get notifications about font substitution for handling font substitution cases. -The code snippets below show how to use corresponding functionality. - -```java -private static void NotificationFontSubstitution() -{ - // Open PDF document - try (Document document = new Document(dataDir + "input.pdf")) - { - // Attach the FontSubstitution event handler - document.FontSubstitution.add(new Document.FontSubstitutionHandler() { - public void invoke(Font font, Font newFont) { - // Handle the font substitution event here, as example - print substituted FontNames into console - System.out.println("Warning: Font " + font.getFontName() + " was substituted with another font -> " - + newFont.getFontName()); - } - }); - - // Save PDF document - document.save(dataDir + "NotificationFontSubstitution_out.pdf"); - } -} -``` - - -### Improve Fonts Embedding using FontSubsetStrategy - -The feature to embed the fonts as a subset can be accomplished by using the isSubset/setSubset property, but sometimes you want to reduce a fully embedded font set to only subsets that are used in the document. -Document has property FontUtilities which includes method SubsetFonts(FontSubsetStrategy subsetStrategy). In the method subsetFonts(), the parameter subsetStrategy helps to tune the subset strategy. FontSubsetStrategy supports two following variants of font subsetting. - -- SubsetAllFonts - This will subset all fonts, used in a document. -- SubsetEmbeddedFontsOnly - This will subset only those fonts which are fully embedded into the document. - -Following code snippet shows how to set FontSubsetStrategy: - -```java - -private static void setFontSubsetStrategy() -{ - // Open PDF document - try (Document document = new Document(dataDir + "input.pdf")) - { - // All fonts will be embedded as subset into document in case of SubsetAllFonts. - document.getFontUtilities().subsetFonts(FontSubsetStrategy.SubsetAllFonts); - - // Font subset will be embedded for fully embedded fonts but fonts which are not embedded into document will not be affected. - document.getFontUtilities().subsetFonts(FontSubsetStrategy.SubsetEmbeddedFontsOnly); - - // Save PDF document - document.save(dataDir + "SetFontSubsetStrategy_out.pdf"); - } -} -``` - ## Get-Set Zoom Factor of PDF File Sometimes, you want to set or get the zoom factor of a PDF document. You can easily accomplish this requirement with Aspose.PDF. diff --git a/en/java/working-with-facades/pdffileeditor/_index.md b/en/java/working-with-facades/pdffileeditor/_index.md index 84886078d..1c05f880a 100644 --- a/en/java/working-with-facades/pdffileeditor/_index.md +++ b/en/java/working-with-facades/pdffileeditor/_index.md @@ -1,10 +1,10 @@ --- -title: PdfFileEditor Class +title: Working with Documents type: docs weight: 10 url: /java/pdffileeditor-class/ description: Discover how to use the PDFFileEditor class in Java to edit and manipulate PDF documents using Aspose.PDF. -lastmod: "2025-02-17" +lastmod: "2025-12-11" sitemap: changefreq: "monthly" priority: 0.7 @@ -14,3 +14,39 @@ sitemap: - [Extract PDF Pages](/pdf/java/extract-pdf-pages/) - [Page Break in existing PDF](/pdf/java/page-break-in-existing-pdf/) + +Working with PDF documents includes various functions. Managing the pages of a PDF file is an important part of this job. com.aspose.facades provide the `PdfFileEditor` class for this purpose. + +PdfFileEditor class contains the methods which help manipulate individual pages; this class doesn't edit or manipulate the contents of a page. You can insert a new page, delete existing page, split the pages or you can specify imposition of the pages using PdfFileEditor. + +The features provided by this class can be divided into three main categories i.e. File Editing, PDF Imposition, and Splitting. We're going to discuss these sections in detail below: + +## File Editing + +The features which we can include in this section are Insert, Append, Delete, Concatenate and Extract. You can insert a new page at a specified location using Insert method, or append the pages at the end of the file. You can also delete any number of pages from the file using Delete method, by specifying an integer array containing the numbers of pages to be deleted. Concatenate method helps you to join pages from multiple PDF files. You can extract any number of pages using Extract method, and save these pages into another PDF file or memory stream. + +This section explores the capabilities of this class and explains the purpose of its methods. + +- [Concatenate PDF documents](/pdf/java/concatenate-pdf-documents/) +- [Extract PDF pages](/pdf/java/extract-pdf-pages/) +- [Insert PDF pages](/pdf/java/insert-pdf-pages/) +- [Delete PDF pages](/pdf/java/delete-pdf-pages/) + +## Using Page Breaks + +Page Break is a special feature that allows to reflow of the document. + +- [Page Break in existing PDF](/pdf/java/page-break-in-existing-pdf/) + +## PDF Imposition + +Imposition is the process of arranging pages correctly prior to printing. `PdfFileEditor` provides two methods for this purpose i.e. `MakeBooklet` and `MakeNUp`. MakeBooklet method helps to arrange pages so that it'll be easy to fold or bind them after printing, however, MakeNUp method allows to print multiple pages on one page of the PDF file. + +- [Make Booklet of PDF](/pdf/java/make-booklet-of-pdf/) +- [Make NUp of PDF files](/pdf/java/make-nup-of-pdf-files/) + +## Splitting + +Splitting feature allows you to divide an existing PDF file into different parts. You can either split the front part of the PDF file or the rear part. As PdfFileEditor provides a variety of method for splitting purposes, you can also split a file into individual pages or many sets of multiple pages. + +- [Split PDF pages](/pdf/java/split-pdf-pages/) \ No newline at end of file diff --git a/en/java/working-with-facades/pdffileeditor/delete-pdf-pages/_index.md b/en/java/working-with-facades/pdffileeditor/delete-pdf-pages/_index.md new file mode 100644 index 000000000..6441c38bc --- /dev/null +++ b/en/java/working-with-facades/pdffileeditor/delete-pdf-pages/_index.md @@ -0,0 +1,63 @@ +--- +title: Delete PDF pages +type: docs +ai_search_scope: pdf_java +ai_search_endpoint: https://docsearch.api.aspose.cloud/ask +weight: 70 +url: /java/delete-pdf-pages/ +description: This section explains how to delete PDF pages with Aspose.PDF Facades using PdfFileEditor class. +lastmod: "2025-12-11" +draft: false +--- + +If you want to delete a number of pages from the PDF file which is residing on the disk then you can use the overload of the +[Delete]method which takes following three parameters: intput file path, array of page numbers to be deleted, and output PDF file path. The second parameter is an integer array representing all of the pages which need to be deleted. The specified pages are removed from the intput file and the result is saved as output file. The following code snippet shows you how to delete PDF pages using file paths. + +```java + +private static void deletePages() +{ + // The path to the documents directory + String dataDir = getDirectory(); + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + // Array of pages to delete + int[] pagesToDelete = new int[] { 1, 2 }; + // Delete pages + pdfEditor.delete(dataDir + "DeletePagesInput.pdf", pagesToDelete, dataDir + "DeletePagesUsingFilePath_out.pdf"); + +} +``` + +## Delete PDF Pages Using Streams + +The `Delete` method of `PdfFileEditor` class also provides an overload which allows you to delete the pages from the input PDF file, while both the input and output files are in the streams. +This overload takes following three parameters: input stream, integer array of PDF pages to be deleted, and output stream. +The following code snippet shows you how to delete PDF pages using streams. + +```java + +private static void deletePagesUsingStreams() +{ + // The path to the documents directory + String dataDir = getDirectory(); + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "DeletePagesInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "DeletePagesUsingStream_out.pdf")) + { + // Array of pages to delete + int[] pagesToDelete = new int[] { 1, 2 }; + // Delete pages + pdfEditor.delete(inputStream, pagesToDelete, outputStream); + } + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` \ No newline at end of file diff --git a/en/java/working-with-facades/pdffileeditor/insert-pdf-pages/_index.md b/en/java/working-with-facades/pdffileeditor/insert-pdf-pages/_index.md new file mode 100644 index 000000000..f7d91aa7a --- /dev/null +++ b/en/java/working-with-facades/pdffileeditor/insert-pdf-pages/_index.md @@ -0,0 +1,123 @@ +--- +title: Insert PDF pages +type: docs +ai_search_scope: pdf_java +ai_search_endpoint: https://docsearch.api.aspose.cloud/ask +weight: 50 +url: /java/insert-pdf-pages/ +description: This section explains how to insert PDF pages with com.aspose.pdf.facades using PdfFileEditor class. +lastmod: "2025-12-11" +draft: false +--- + + +## Insert PDF Pages Between Two Numbers Using File Paths + +A particular range of pages can be inserted from one PDF into another using [Insert] method of [PdfFileEditor] class. +In order to do that, you need an input PDF file in which you want to insert the pages, a port file from which the pages need to be taken for insertion, a location where the pages are to be inserted, and a range of pages of the port file which have to be inserted in the input PDF file. This range is specified with start page and end page parameters. Finally, the output PDF file is saved with the specified range of pages inserted in the input file. The following code snippet shows you how to insert PDF pages between two numbers using file streams. + +```java +private static void insertPdfPagesBetweenTwoNumbersUsingFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Insert pages + pdfEditor.insert( + dataDir + "MultiplePages.pdf", 1, + dataDir + "InsertPages.pdf", 2, 5, + dataDir + "InsertPagesBetweenNumbers_out.pdf"); +} +``` + +## Insert Array of PDF Pages Using File Paths + +If you want to insert some specified pages into another PDF file, then you can use an overload of the [Insert] method which requires an integer array of pages. +In this array, you can specify which particular pages you want to insert in the input PDF file. In order to do that, you need an input PDF file in which you want to insert the pages, a port file from which the pages need to be taken for insertion, a location where the pages are to be inserted, and integer array of the pages from port file which have to be inserted in the input PDF file. This array contains a list of particular pages which you’re interested to insert in the input PDF file. Finally, the output PDF file is saved with the specified array of pages inserted in the input file. +The following code snippet shows you how to insert array of PDF pages using file paths. + +```java + +private static void insertArrayOfPdfPagesUsingFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + int[] pagesToInsert = new int[] { 2, 3 }; + // Insert pages + pdfEditor.insert( + dataDir + "MultiplePages.pdf", 1, + dataDir + "InsertPages.pdf", pagesToInsert, + dataDir + "InsertArrayOfPages_out.pdf"); +} +``` + +## Insert PDF Pages between Two Numbers Using Streams + +If you want to insert the range of pages using streams, you only need to use the appropriate overload of the [Insert] method of [PdfFileEditor] class. +In order to do that, you need an input PDF stream in which you want to insert the pages, a port stream from which the pages need to be taken for insertion, a location where the pages are to be inserted, and a range of pages of the port stream which have to be inserted in the input PDF stream. This range is specified with start page and end page parameters. Finally, the output PDF stream is saved with the specified range of pages inserted in the input stream. The following code snippet shows you how to insert PDF pages between two numbers using streams. + +```java + +private static void insertPdfPagesBetweenTwoNumbersUsingStreams() +{ + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MultiplePages.pdf")) + { + try (FileInputStream portStream = new FileInputStream(dataDir + "InsertPages.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "InsertPagesBetweenNumbersUsingStreams_out.pdf")) + { + // Insert pages + pdfEditor.insert(inputStream, 1, portStream, 1, 4, outputStream); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Insert Array of PDF Pages Using Streams + +You can also insert an array of pages into another PDF file using streams with the helps of appropriate overload of the Insert method which requires an integer array of pages. In this array, you can specify which particular pages you want to insert in the input PDF stream. In order to do that, you need an input PDF stream in which you want to insert the pages, a port stream from which the pages need to be taken for insertion, a location where the pages are to be inserted, and integer array of the pages from port stream which have to be inserted in the input PDF file. This array contains a list of particular pages which you’re interested to insert in the input PDF stream. Finally, the output PDF stream is saved with the specified array of pages inserted in the input file.The following code snippet shows you how to insert array of PDF pages using streams. + +```java + +private static void insertArrayOfPdfPagesUsingStreams() +{ + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + // Pages to insert + int[] pagesToInsert = new int[] { 2, 3 }; + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MultiplePages.pdf")) + { + try (FileInputStream portStream = new FileInputStream(dataDir + "InsertPages.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "InsertPagesBetweenNumbersUsingStreams_out.pdf")) + { + // Insert pages + pdfEditor.insert(inputStream, 1, portStream, pagesToInsert, outputStream); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` \ No newline at end of file diff --git a/en/java/working-with-facades/pdffileeditor/make-booklet-of-pdf/_index.md b/en/java/working-with-facades/pdffileeditor/make-booklet-of-pdf/_index.md new file mode 100644 index 000000000..eaaae6b52 --- /dev/null +++ b/en/java/working-with-facades/pdffileeditor/make-booklet-of-pdf/_index.md @@ -0,0 +1,240 @@ +--- +title: Make Booklet of PDF +type: docs +ai_search_scope: pdf_java +ai_search_endpoint: https://docsearch.api.aspose.cloud/ask +weight: 80 +url: /java/make-booklet-of-pdf/ +description: This section explains how to make booklet of PDF with com.aspose.pdf.facades using PdfFileEditor class. +lastmod: "2025-12-11" +draft: false +--- + + +## Make Booklet of PDF Using File Paths + +[MakeBooklet] method of [PdfFileEditor]class allows you to make booklet of the input PDF file and save it to the output PDF file. +This overload allows you to make booklet using file paths. The following code snippet shows you how to make booklet using file paths. + +```java + +private static void makeBookletOfPdfUsingFilePaths() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Make booklet + pdfEditor.makeBooklet(dataDir + "MakeBookletInput.pdf", dataDir + "MakeBookletUsingPaths_out.pdf"); + } +``` + +## Make Booklet of PDF Using Page Size and File Paths + +[MakeBooklet] method of [PdfFileEditor]class allows you to make booklet of the input PDF file and save it to the output PDF file. +This overload allows you to make booklet using file paths. You can also set the page size of the output PDF file with this overlaod. +The following code snippet shows you how to make booklet using page size and file paths. + +```java + +private static void makeBookletOfPdfUsingPageSizeAndFilePaths() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Make booklet + pdfEditor.makeBooklet(dataDir + "MakeBookletInput.pdf", + dataDir + "MakeBookletUsingPaths_out.pdf", PageSize.getA5()); +} +``` + +## Make Booklet of PDF Using Page Size, Specified Left and Right Pages, and File Paths + +[MakeBooklet]method of [PdfFileEditor] class allows you to make booklet of the input PDF file and save it to the output PDF file. +This overload allows you to make booklet using file paths. +You can also set the page size of the output PDF file and specify particular pages for the left and right sides of the output PDF file with this overlaod. +The following code snippet shows you how to make booklet using page size, specified left and right pages and file paths. + + +```java + +private static void makeBookletOfPdfUsingPageSizeSpecifiedLeftAndRightPagesAndFilePaths() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Set left and right pages + int[] leftPages = new int[] { 1, 5 }; + int[] rightPages = new int[] { 2, 3 }; + // Make booklet + pdfEditor.makeBooklet(dataDir + "MakeBookletInput.pdf", + dataDir + "MakeBookletUsingPaths_out.pdf", PageSize.getA5(), leftPages, rightPages); +} + +``` + +## Make Booklet of PDF Using Specified Left and Right Pages, and File Paths + +[MakeBooklet] method of [PdfFileEditor] class allows you to make booklet of the input PDF file and save it to the output PDF file. +This overload allows you to make booklet using file paths. You can also specify particular pages for the left and right sides of the output PDF file with this overload. +The following code snippet shows you how to make booklet using specified left and right pages and file paths. + +```java + +private static void makeBookletOfPdfUsingSpecifiedLeftAndRightPagesAndFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Set left and right pages + int[] leftPages = new int[] { 1, 5 }; + int[] rightPages = new int[] { 2, 3 }; + // Make booklet + pdfEditor.makeBooklet(dataDir + "MakeBookletInput.pdf", + dataDir + "MakeBookletUsingPaths_out.pdf", leftPages, rightPages); +} +``` + +## Make Booklet of PDF Using Streams + +[MakeBooklet]method of [PdfFileEditor]class allows you to make booklet of the input PDF stream and save it to the output PDF streams. +This overload allows you to make booklet using streams instead of file paths. The following code snippet shows you how to make booklet using streams. + +```java +private static void makeBookletOfPdfUsingStreams() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeBookletInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeBookletUsingStreams_out.pdf")) + { + // Make booklet + pdfEditor.makeBooklet(inputStream, outputStream); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Make Booklet of PDF Using Page Size and Streams + +[MakeBooklet] method of [PdfFileEditor]class allows you to make booklet of the input PDF stream and save it to the output PDF stream. +This overload allows you to make booklet using streams instead of file paths. You can also set the page size of the output PDF stream with this overload. +The following code snippet shows you how to make booklet using page size and streams. + +```java + +private static void makeBookletOfPdfUsingPageSizeAndStreams() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeBookletInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeBookletUsingStreams_out.pdf")) + { + // Make booklet + pdfEditor.makeBooklet(inputStream, outputStream, PageSize.getA5()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Make Booklet of PDF Using Page Size, Specified Left and Right Pages, and Streams + +[MakeBooklet] method of [PdfFileEditor] class allows you to make booklet of the input PDF stream and save it to the output PDF stream. +This overload allows you to make booklet using streams instead of file paths. You can also set the page size of the output PDF file and specify particular pages for the left and right sides of the output PDF stream with this overload. The following code snippet shows you how to make booklet using page size, specified left and right pages, and streams. + +```java + +private static void makeBookletOfPdfUsingPageSizeSpecifiedLeftAndRightPagesAndStreams() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeBookletInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeBookletUsingStreams_out.pdf")) + { + + // Set left and right pages + int[] leftPages = new int[] { 1, 5 }; + int[] rightPages = new int[] { 2, 3 }; + + // Make booklet + pdfEditor.makeBooklet(inputStream, outputStream, PageSize.getA5(), leftPages, rightPages); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Make Booklet of PDF Using Specified Left and Right Pages, and Streams + +[MakeBooklet] method of [PdfFileEditor]class allows you to make booklet of the input PDF stream and save it to the output PDF stream. +This overload allows you to make booklet using streams instead of file paths. You can also specify particular pages for the left and right sides of the output PDF stream with this overlaod. The following code snippet shows you how to make booklet using specified left and right pages and streams. + +```java + +private static void makeBookletOfPdfUsingSpecifiedLeftAndRightPagesAndStreams() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeBookletInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeBookletUsingStreams_out.pdf")) + { + + // Set left and right pages + int[] leftPages = new int[] { 1, 5 }; + int[] rightPages = new int[] { 2, 3 }; + + // Make booklet + pdfEditor.makeBooklet(inputStream, outputStream, leftPages, rightPages); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` \ No newline at end of file diff --git a/en/java/working-with-facades/pdffileeditor/make-nup-of-pdf-files/_index.md b/en/java/working-with-facades/pdffileeditor/make-nup-of-pdf-files/_index.md new file mode 100644 index 000000000..77adeb732 --- /dev/null +++ b/en/java/working-with-facades/pdffileeditor/make-nup-of-pdf-files/_index.md @@ -0,0 +1,224 @@ +--- +title: Make NUp of PDF files +type: docs +ai_search_scope: pdf_java +ai_search_endpoint: https://docsearch.api.aspose.cloud/ask +weight: 90 +url: /java/make-nup-of-pdf-files/ +description: This article shows how to make NUp of PDF files work with com.aspose.pdf.facades using PdfFileEditor class. +lastmod: "2025-12-11" +draft: false +--- + + +## Make NUp of PDF Using File Paths + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of the input PDF file and save it to the output PDF file. +This overload allows you to make NUp using file paths.The following code snippet shows you how to make NUP using file paths. + +```java + +private static void makeNupOfPdfUsingFilePaths() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Make NUp + pdfEditor.makeNUp(dataDir + "MakeNupInput.pdf", dataDir + "MakeNupInput2.pdf", "MakeNUpUsingPaths_out.pdf"); + +} +``` + +## Make NUp Using Page Size and File Paths + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of the input PDF file and save it to the output PDF file. +This overload allows you to make NUp using file paths. You can also set the page size of the output PDF file using this overload.The following code snippet shows you how to make NUp using page size and file paths. + +```java + +private static void MakeNupUsingPageSizeAndFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Make NUp + pdfEditor.makeNUp(dataDir + "MakeNupMultiplePagesInput.pdf", dataDir + "MakeNUpUsingPageSizeAndPaths_out.pdf", 2, 3, + PageSize.getA5()); +} +``` + +## Make NUp of PDF Using Page Size, Horizontal and Vertical Values, and File Paths + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of the input PDF file and save it to the output PDF file. +This overload allows you to make NUp using file paths. You can also set the page size of the output PDF file and horizontal and vertical number of pages on each output page using this overload. The following code snippet shows you how to make NUp using page size, horizontal and vertical values, and file paths. + +```java + +private static void MakeNupOfPdfUsingPageSizeHorizontalAndVerticalValuesAndFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Make NUp + pdfEditor.makeNUp(dataDir + "MakeNupInput.pdf", "MakeNUpUsingPageSizeHorizontalAndVerticalValues_out.pdf", 2, 3); +} +``` + +## Make NUp of PDF Using Array Of PDF Files and File Paths + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of an array of input PDF files and save them to a single output PDF file. +This overload allows you to make NUp using file paths.The following code snippet shows you hot make NUp using array of PDF files and file paths. + +```java + +private static void MakeNupOfPdfUsingArrayOfPdfFilesAndFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + String[] filesArray = new String[2]; + filesArray[0] = dataDir + "MakeNupInput.pdf"; + filesArray[1] = dataDir + "MakeNupInput2.pdf"; + // Make NUp + pdfEditor.makeNUp(filesArray, dataDir + "MakeNupUsingArrayOfFilesAndPaths_out.pdf", true); +} +``` + +## Make NUp of PDF Using Streams + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of the input PDF stream and save it to the output PDF stream. + This overload allows you to make NUp using streams instead of file paths. The following code snippet shows you how to make NUp using streams. + +```java + +private static void MakeNupOfPdfUsingStreams() +{ + + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream1 = new FileInputStream(dataDir + "MakeNupInput.pdf")) + { + try (FileInputStream inputStream2 = new FileInputStream(dataDir + "MakeNupInput2.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeNUpUsingStreams_out.pdf")) + { + // Make NUp + pdfEditor.makeNUp(inputStream1, inputStream2, outputStream); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Make NUp of PDF Using Page Size and Streams + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of the input PDF stream and save it to the output PDF stream. +This overload allows you to make NUp using streams instead of file paths. You can also set the page size of the output PDF stream using this overload. The following code snippet shows you how to make NUp using page size and streams. + +```java + +private static void MakeNupOfPdfUsingPageSizeAndStreams() +{ + // The path to the documents directory + String dataDir = "C:\\Workspace\\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeNupInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeNUpUsingStreams_out.pdf")) + { + // Make NUp + pdfEditor.makeNUp(inputStream, outputStream, 2, 3, PageSize.getA5()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Make NUp of PDF Using Page Size, Horizontal and Vertical Values, and Streams + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of the input PDF stream and save it to the output PDF stream. +This overload allows you to make NUp using streams instead of file paths. You can also set the page size of the output PDF stream and horizontal and vertical number of pages on each output page using this overload. The following code snippet shows you how to make NUp using page size, horizontal and vertical values, and streams. + +```java + +private static void MakeNupOfPdfUsingPageSizeHorizontalAndVerticalValuesAndStreams() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeNupInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeNUpUsingStreams_out.pdf")) + { + // Make NUp + pdfEditor.makeNUp(inputStream, outputStream, 2, 3); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Make NUp of PDF Using Array Of PDF Files and Streams + +[MakeNUp] method of [PdfFileEditor] class allows you to make NUp of an array of input PDF streams and save them to a single output PDF stream. +This overload allows you to make NUp using streams instead of file paths. The following code snippet shows you how to make NUp using array of PDF files using streams. + +```java + +private static void MakeNupOfPdfUsingArrayOfPdfFilesAndStreams() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream1 = new FileInputStream(dataDir + "MakeNupInput.pdf")) + { + try (FileInputStream inputStream2 = new FileInputStream(dataDir + "MakeNupInput2.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeNUpUsingStreams_out.pdf")) + { + FileInputStream[] fileStreams = new FileInputStream[2]; + fileStreams[0] = inputStream1; + fileStreams[1] = inputStream2; + // Make NUp + pdfEditor.makeNUp(fileStreams, outputStream); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` \ No newline at end of file diff --git a/en/java/working-with-facades/pdffileeditor/split-pdf-pages/_index.md b/en/java/working-with-facades/pdffileeditor/split-pdf-pages/_index.md new file mode 100644 index 000000000..046ab574b --- /dev/null +++ b/en/java/working-with-facades/pdffileeditor/split-pdf-pages/_index.md @@ -0,0 +1,272 @@ +--- +title: Split PDF pages +type: docs +ai_search_scope: pdf_java +ai_search_endpoint: https://docsearch.api.aspose.cloud/ask +weight: 60 +url: /java/split-pdf-pages/ +description: This section explains how to split PDF pages with com.aspose.pdf.facades Facades using PdfFileEditor class. +lastmod: "2025-12-11" +draft: false +--- + + +## Split PDF Pages from First Using File Paths + +[SplitFromFirst] method of [PdfFileEditor] class allows you to split the PDF file starting from the first page and ending at the specified page number. +If you want to manipulate the PDF files from the disk, you can pass the file paths of the intput and output PDF files to this method. The following code snippet shows you how to split PDF pages from first using file paths. + +```java + +private static void SplitPdfPagesFromFirstUsingFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Split pages + pdfEditor.splitFromFirst(dataDir + "MultiplePages.pdf", 3, dataDir + "SplitPagesUsingPaths_out.pdf"); + +} +``` + +## Split PDF Pages from First Using File Streams + +[SplitFromFirst] method of [PdfFileEditor] class allows you to split the PDF file starting from the first page and ending at the specified page number. +If you want to manipulate the PDF files from the streams, you can pass the input and output PDF streams to this method. The following code snippet shows you how to split PDF pages from first using file streams. + +```java + +private static void SplitPdfPagesFromFirstUsingFileStreams() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "MakeBookletInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeBookletUsingStreams_out.pdf")) + { + // Split pages + pdfEditor.splitFromFirst(inputStream, 3, outputStream); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + +} +``` + +## Split PDF Pages to Bulk Using File Paths + +[SplitToBulks] method of [PdfFileEditor] class allows you to split the PDF file into multiple sets of pages. +In this example, we require two sets of pages (1, 2) and (5, 6). If you want to access the PDF file from the disk, you need to pass the input PDF as file path. This method returns an array of MemoryStream. You can loop through this array and save the individual sets of pages as separate files. The following code snippet shows you how to split PDF pages to bulk using file paths. + +```java + +private static void SplitPdfPagesToBulkUsingFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + int fileNumber = 1; + // Create array of pages to split + int[][] numberOfPages = new int[][] { new int[] { 1, 2 }, new int[] { 3, 4 } }; + // Split to bulk + ByteArrayInputStream[] outBuffer = pdfEditor.splitToBulks(dataDir + "MultiplePages.pdf", numberOfPages); + // Save individual files + for (ByteArrayInputStream outStream : outBuffer) + { + try (FileOutputStream outFileStream = new FileOutputStream(dataDir + "File_" + fileNumber + "_out.pdf")) + { + // Convert ByteArrayInputStream to byte array and write + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = outStream.read(buffer)) != -1) { + outFileStream.write(buffer, 0, bytesRead); + } + fileNumber++; + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} +``` + +## Split PDF Pages to Bulk Using Streams + +[SplitToBulks] method of [PdfFileEditor] class allows you to split the PDF file into multiple sets of pages. +In this example, we require two sets of pages (1, 2) and (5, 6). You can pass a stream to this method instead of accessing the file from the disk. This method returns an array of MemoryStream. You can loop through this array and save the individual sets of pages as separate files. The following code snippet shows you how to split PDF pages to bulk using streams. + +```java + +private static void SplitPdfPagesToBulkUsingStreams() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + try (FileInputStream inputStream1 = new FileInputStream(dataDir + "splitPdfToIndividualPagesInput.pdf")) { + int fileNumber = 1; + // Create array of pages to split + int[][] numberOfPages = new int[][]{new int[]{1, 2}, new int[]{3, 4}}; + // Split to bulk + + ByteArrayInputStream[] outBuffer = pdfEditor.splitToBulks(inputStream1, numberOfPages); + // Save individual files + for (ByteArrayInputStream outStream : outBuffer) { + try (FileOutputStream outFileStream = new FileOutputStream(dataDir + "File_" + fileNumber + "_out.pdf")) { + // Convert ByteArrayInputStream to byte array and write + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = outStream.read(buffer)) != -1) { + outFileStream.write(buffer, 0, bytesRead); + } + fileNumber++; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Split PDF Pages to End Using File Paths + +[SplitToEnd] method of [PdfFileEditor] class allows you to split the PDF from the specified page number to the end of the PDF file and save it as a new PDF. +In order to do this, using file paths, you need to pass input and output file paths and the page number from where the split needs to be started. The output PDF will be saved to the disk. The following code snippet shows you how to split PDF pages to end using file paths. + +```java + +private static void SplitPdfPagesToEndUsingFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Split pages + pdfEditor.splitToEnd(dataDir + "MultiplePages.pdf", 3, dataDir + "SplitPagesToEndUsingPaths_out.pdf"); +} +``` + +## Split PDF Pages to End Using Streams + +[SplitToEnd] method of [PdfFileEditor] class allows you to split the PDF from the specified page number to the end of the PDF file and save it as a new PDF. +In order to do this, using streams, you need to pass input and output streams and the page number from where the split needs to be started. +The output PDF will be saved to the output stream. The following code snippet shows you how to split PDF pages to end using streams. + +```java + +private static void SplitPdfPagesToEndUsingStreams() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + // Create streams + try (FileInputStream inputStream = new FileInputStream(dataDir + "splitPdfToIndividualPagesInput.pdf")) + { + try (FileOutputStream outputStream = new FileOutputStream(dataDir + "MakeNUpUsingStreams_out.pdf")) + { + // Split pages + pdfEditor.splitToEnd(inputStream, 3, outputStream); + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` + +## Split PDF to Individual Pages Using File Paths + +{{% alert color="primary" %}} + +You can try to split PDF document and view the results online at this link: + +[products.aspose.app/pdf/splitter](https://products.aspose.app/pdf/splitter) {{% /alert %}} + +In order to split PDF file to individual pages, you need to pass the PDF as file path to the [SplitToPages](https://reference.aspose.com/pdf/java/aspose.pdf.facades/pdffileeditor/methods/splittopages/index) method. This method will return an array of MemoryStream containing individual pages of the PDF file. You can loop through this array of MemoryStream and save individual pages as individual PDF files on the disk. The following code snippet shows you how to split PDF to individual pages using file paths. + +```java + +private static void SplitPdfToIndividualPagesUsingFilePaths() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + int fileNumber = 1; + ByteArrayInputStream[] outBuffer = pdfEditor.splitToPages(dataDir + "splitPdfToIndividualPagesInput.pdf"); + // Save individual files + for (ByteArrayInputStream outStream : outBuffer) { + try (FileOutputStream outFileStream = new FileOutputStream(dataDir + "File_" + fileNumber + "_out.pdf")) { + // Convert ByteArrayInputStream to byte array and write + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = outStream.read(buffer)) != -1) { + outFileStream.write(buffer, 0, bytesRead); + } + fileNumber++; + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} +``` + +## Split PDF to Individual Pages Using Streams + +In order to split PDF file to individual pages, you need to pass the PDF as stream to the [SplitToPages] method. + This method will return an array of MemoryStream containing individual pages of the PDF file. + You can loop through this array of MemoryStream and save individual pages as individual PDF files on the disk, or you can keep these individual pages in the memory stream for later use in your application. The following code snippet shows you how to split PDF to individual pages using streams. + +```java + +private static void SplitPdfToIndividualPagesUsingStreams() +{ + // The path to the documents directory + String dataDir = "C:\Workspace\"; + + // Create PdfFileEditor object + com.aspose.pdf.facades.PdfFileEditor pdfEditor = new com.aspose.pdf.facades.PdfFileEditor(); + + try (FileInputStream inputStream = new FileInputStream(dataDir + "splitPdfToIndividualPagesInput.pdf")) { + int fileNumber = 1; + ByteArrayInputStream[] outBuffer = pdfEditor.splitToPages(inputStream); + // Save individual files + for (ByteArrayInputStream outStream : outBuffer) { + try (FileOutputStream outFileStream = new FileOutputStream(dataDir + "File_" + fileNumber + "_out.pdf")) { + // Convert ByteArrayInputStream to byte array and write + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = outStream.read(buffer)) != -1) { + outFileStream.write(buffer, 0, bytesRead); + } + fileNumber++; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } +} +``` \ No newline at end of file