---
Product: Aspose.PDF
Platform: java
Page Type: kb
Canonical URL: https://kb.aspose.org/pdf/java/how-to-work-with-facades-java
---

# How to Work with PDF Facades in Java

Use PdfAnnotationEditor, PdfBookmarkEditor, PdfContentEditor, PdfExtractor, and PdfFileSecurity in Aspose.PDF FOSS for Java.

## Flatten Annotations

Flatten all annotations into the page content stream so they are no longer editable
or removable as separate annotation objects. This is a common step before printing
or archiving a document:

```java
try (PdfAnnotationEditor editor = new PdfAnnotationEditor()) {
    editor.bindPdf("annotated.pdf");
    editor.flattenAnnotations();
    editor.save("flat.pdf");
}
```

## Remove Bookmarks

Delete all outline bookmarks from a document. Bookmarks (also called outlines) are the
navigation tree entries visible in PDF reader sidebars:

```java
try (PdfBookmarkEditor editor = new PdfBookmarkEditor()) {
    editor.bindPdf("input.pdf");
    editor.deleteBookmarks();
    editor.save("no-bookmarks.pdf");
}
```

## Replace Text

Substitute a string in all pages of a document. This is useful for filling in template
placeholders before distributing a document:

```java
try (PdfContentEditor editor = new PdfContentEditor()) {
    editor.bindPdf("template.pdf");
    editor.replaceText("{{Date}}", "2026-05-24");
    editor.save("output.pdf");
}
```

## Encrypt a Document

Apply AES-256 encryption with access permissions using `PdfFileSecurity`. The
`DocumentPrivilege.getForbidAll()` preset disables all operations; individual permissions
can then be re-enabled with setter methods:

```java
try (PdfFileSecurity security = new PdfFileSecurity("input.pdf", "secured.pdf")) {
    DocumentPrivilege priv = DocumentPrivilege.getForbidAll();
    priv.setAllowPrint(true);
    security.encryptFile("user", "owner", priv, KeySize.x256);
}
```

## Extract Text

Iterate over page text using `PdfExtractor`. Call `extractText()` first to process
all pages, then retrieve each page's text with `getNextPageText()`:

```java
try (PdfExtractor extractor = new PdfExtractor()) {
    extractor.bindPdf("document.pdf");
    extractor.extractText();
    while (extractor.hasNextPageText()) {
        String text = extractor.getNextPageText();
        System.out.println(text);
    }
}
```

## See Also

- [Aspose.PDF for Java — Enterprise Knowledge Base](https://kb.aspose.com/pdf/java/)