Represents a document that can be opened, edited, and exported in various formats. Provides a unified interface for working with different document types including PDF, Word, Excel, and more.
from nutrient_sdk import DocumentConstruction
Document()Creates a new Document instance with default settings.
Class Methods
open
@classmethoddef open(cls, file_path: str) -> Document@classmethoddef open(cls, file_path: str, settings: DocumentSettings) -> DocumentOpens a document from a file path using default settings.
Parameters:
| Name | Type | Description |
|---|---|---|
file_path | str | The path to the document file to open. |
settings (optional) | DocumentSettings | The settings to use when opening the document. |
Returns: Document - A new Document instance representing the opened document.
Methods
export
def export(self, filepath: str, exporter: IExporter) -> NoneExports the document to a file using the specified exporter.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The path where the exported file will be saved. |
exporter | IExporter | The exporter that defines the output format and settings. |
export_as_html
def export_as_html(self, filepath: str) -> NoneExports the document as HTML format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the HTML document will be saved. |
export_as_image
def export_as_image(self, filepath: str) -> NoneExports the document as image format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the image document will be saved. |
export_as_markdown
def export_as_markdown(self, filepath: str) -> NoneExports the document as Markdown format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the Markdown document will be saved. |
export_as_pdf
def export_as_pdf(self, filepath: str) -> NoneExports the document as PDF format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the PDF document will be saved. |
export_as_presentation
def export_as_presentation(self, filepath: str) -> NoneExports the document as presentation format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the presentation document will be saved. |
export_as_spreadsheet
def export_as_spreadsheet(self, filepath: str) -> NoneExports the document as spreadsheet format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the spreadsheet document will be saved. |
export_as_svg
def export_as_svg(self, filepath: str) -> NoneExports the document as SVG format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the SVG document will be saved. |
export_as_text
def export_as_text(self, filepath: str) -> NoneExports the document as Text format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the Text document will be saved. |
export_as_word
def export_as_word(self, filepath: str) -> NoneExports the document as Word format to the specified file path.
Parameters:
| Name | Type | Description |
|---|---|---|
filepath | str | The file path where the Word document will be saved. |
Properties
page_count
@propertydef page_count(self) -> intThe total number of pages in the document.
Type: int
Read-only property.
settings
@propertydef settings(self) -> DocumentSettingsThe settings associated with this document instance.
Type: DocumentSettings
Read-only property.
underlying_type
@propertydef underlying_type(self) -> DocumentTypeThe underlying document type (PDF, Word, Excel, etc.) of the opened document.
Type: DocumentType
Read-only property.
Context manager
Document supports the context manager protocol. Use with to ensure native resources are released automatically:
with Document.open(...) as document: # ... use document ... pass # closed automatically on exitOr close explicitly:
document = Document.open(...)try: # ... use document ... passfinally: document.close()