Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 38 additions & 2 deletions en/java/working-with-facades/pdffileeditor/_index.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/)
Original file line number Diff line number Diff line change
@@ -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);
}
}
```
123 changes: 123 additions & 0 deletions en/java/working-with-facades/pdffileeditor/insert-pdf-pages/_index.md
Original file line number Diff line number Diff line change
@@ -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);
}
}
```
Loading