Provides specialized editing capabilities for PDF documents. Implements document and page-based editing operations specific to PDF format.
from nutrient_sdk import PdfEditorConstruction
PdfEditor cannot be instantiated directly. Obtain instances through static factory methods or via other SDK classes.
Class Methods
edit
@classmethoddef edit(cls, document: Document) -> PdfEditorCreates a new PdfEditor instance and begins editing the specified document.
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The document to edit. |
Returns: PdfEditor - A new PdfEditor instance for editing the document.
Methods
append_document
def append_document(self, document: Document) -> NoneAppends all pages from another document to the end of the current PDF document.
Parameters:
| Name | Type | Description |
|---|---|---|
document | Document | The document to append to the current PDF document. |
close
def close(self) -> NoneCloses the current document’s editing context without disposing the editor. The editor remains available for another editing operation.
detect_and_add_form_fields
def detect_and_add_form_fields(self) -> NoneDetects form fields on every page of the document and adds matching interactive form fields to the PDF. Detection uses the Vision form pipeline; detected fields are converted into AcroForm form fields placed at the detected positions.
make_searchable
def make_searchable(self) -> NoneRuns OCR over every page in the document and writes an invisible, searchable text layer on top of the rendered page content.
save
def save(self) -> NoneSaves the current changes made in the editor.
save_as
def save_as(self, path: str) -> NoneSaves the current changes to a file at the specified path.
Parameters:
| Name | Type | Description |
|---|---|---|
path | str | The file path where the document will be saved. |
Properties
form_field_collection
@propertydef form_field_collection(self) -> listThe collection of form fields in the PDF document.
Type: list
Read-only property.
metadata
@propertydef metadata(self) -> PdfMetadataThe metadata associated with the current PDF document.
Type: PdfMetadata
Read-only property.
page_collection
@propertydef page_collection(self) -> listThe collection of pages in the PDF document.
Type: list
Read-only property.
Context manager
PdfEditor supports the context manager protocol. Use with to ensure native resources are released automatically:
with PdfEditor.edit(...) as pdf_editor: # ... use pdf_editor ... pass # released automatically on exitOr manage it explicitly. Closing the document and releasing the object are two different operations:
pdf_editor = PdfEditor.edit(...)try: # ... use pdf_editor ... pdf_editor.close() # close the document; the object stays usablefinally: pdf_editor.dispose() # close it and release the native handleclose() closes the document currently being edited and leaves this object usable: call edit() again to edit another document. It does not release the native handle.
dispose() ends this object’s life. It closes the document first — that is what hands ownership of a converted document back to the SDK — and then releases the handle. Leaving a with block does the same. Calling it more than once has no effect.
An object that is never disposed has its handle reclaimed when it is garbage collected, but that is a safety net rather than a substitute: it releases the handle without closing the document, and finalization runs at an unpredictable time.