Edit text in PDFs on Android
Starting with Nutrient Android SDK 8.7, you can edit text directly in PDF documents using the built-in user interface. You can also change text color, font type, and font size, as well as set the font style to bold or italic. Content editing uses the native text input system, enabling all the text manipulation features and gestures common on Android.
License
To edit text directly in PDF documents, contact Sales to add content editing to your license.
Enabling and disabling content editing
If your license includes the content editing feature, it’s enabled by default, and the Content Editor item will show up on the main action bar. If you want to disable it, use PdfActivityConfiguration.Builder
:
val config = PdfActivityConfiguration.Builder(context) .contentEditingEnabled(false) .build()
final PdfActivityConfiguration config = new PdfActivityConfiguration.Builder(context) .contentEditingEnabled(false) .build();
You can also use PdfConfiguration.Builder
:
val config = PdfConfiguration.Builder() .contentEditingEnabled(false) .build()
PdfConfiguration config = new PdfConfiguration.Builder() .contentEditingEnabled(false) .build();
Both will remove the Content Editor item from the action bar.
Editing text in a PDF using the built-in UI
To edit text in a PDF using the built-in UI, follow these steps:
-
On the main action bar, tap the Content Editor button.
-
Tap within a text box on the page.
-
Add or delete content in the text box.
-
On the keyboard accessory toolbar, change the text color, the font type, or the font size, or set the font style to bold or italic.
-
On the content editing toolbar, click the Save button to save your changes.
Paragraph editing
Prior to version 2024.1, you could only edit single lines of text. Now, we support editing of whole paragraphs. Although the concept of paragraphs doesn’t exist in the PDF format, our editing engine recognizes lines that belong together and groups them into paragraphs, which can be edited as an entity. This new feature includes the ability to:
-
Create new paragraphs and delete existing ones.
-
Copy/paste text and paragraphs.
-
Resize and reposition paragraphs using drag and drop.
-
Change the text alignment of a paragraph (left/center/right/justified).
Triggering the content editing mode programmatically
You can enter content editing mode in your code by calling PdfFragment#enterContentEditingMode
:
pdfFragment.enterContentEditingMode()
getPdfFragment(). enterContentEditingMode();
Supported text editing functionalities
The following text editing functionalities are supported:
-
Adding or changing the text colors and font types supported by Nutrient.
-
Adding or changing the text font size.
-
Adding or changing the text to bold and italic.
-
Undo/redo
-
Selecting the text with the native text selection handles or text selection gestures in the software keyboard.
-
Editing the text using a hardware keyboard paired with your device.
Limitations
Text editing currently comes with the following limitations:
-
You can only edit left-to-right (LTR) text.
-
Copying and pasting a paragraph with all its style information only works within the content editing session where the copy was made, and only within the same document. However, the plain text information can be pasted outside of the session or document.