PDF Export — Aspose.Note FOSS for Python

Aspose.Note FOSS for Python supports exporting loaded .one documents to PDF via Document.Save(). PDF rendering is provided by the optional ReportLab library. This is the only save format currently implemented; other SaveFormat values raise UnsupportedSaveFormatException.


Prerequisites

Install the library with the [pdf] extra to pull in ReportLab:

pip install "aspose-note[pdf]"

Verify:

python -c "from aspose.note import Document, SaveFormat; print('aspose-note ready')"

Basic Export

Export all pages of a document to a single PDF file:

from aspose.note import Document, SaveFormat

doc = Document("MyNotes.one")
doc.Save("output.pdf", SaveFormat.Pdf)

Pages appear in the PDF in the same order as they appear in the DOM.


Using PdfSaveOptions

PdfSaveOptions provides fine-grained control over the export. Pass it instead of the bare SaveFormat enum:

from aspose.note import Document
from aspose.note.saving import PdfSaveOptions

opts = PdfSaveOptions()

doc = Document("MyNotes.one")
doc.Save("output.pdf", opts)

Note on PageIndex / PageCount: These fields exist on PdfSaveOptions but are not forwarded to the PDF exporter in v26.3.1 and have no effect. The entire document is always exported.


PdfSaveOptions Reference

PropertyTypeDefaultDescription
PageIndexint0Field exists but not forwarded to PDF exporter in v26.3.1 (has no effect)
PageCountint | NoneNoneField exists but not forwarded to PDF exporter in v26.3.1 (has no effect)

Batch Export

PDF is an export-only format for this library. The Document model accepts .one files as input and saves to PDF as output; the reverse direction (PDF as input) is not supported.

Export every .one file in a directory to PDF:

from pathlib import Path
from aspose.note import Document, SaveFormat

input_dir = Path("./notes")
output_dir = Path("./pdfs")
output_dir.mkdir(parents=True, exist_ok=True)

for one_file in sorted(input_dir.glob("*.one")):
    try:
        doc = Document(str(one_file))
        out = output_dir / one_file.with_suffix(".pdf").name
        doc.Save(str(out), SaveFormat.Pdf)
        print(f"OK  {one_file.name} -> {out.name}")
    except Exception as exc:
        print(f"ERR {one_file.name}: {exc}")

Load from Stream, Save to File

Combine stream-based loading with file-based PDF output:

from pathlib import Path
from aspose.note import Document, SaveFormat

one_bytes = Path("MyNotes.one").read_bytes()

import io
doc = Document(io.BytesIO(one_bytes))
doc.Save("output.pdf", SaveFormat.Pdf)

Get PDF Bytes In-Memory

Document.Save() accepts a binary stream directly: no temporary file needed:

import io
from aspose.note import Document, SaveFormat
from aspose.note.saving import PdfSaveOptions

doc = Document("MyNotes.one")

buf = io.BytesIO()
doc.Save(buf, PdfSaveOptions())
pdf_bytes = buf.getvalue()
print(f"PDF size: {len(pdf_bytes)} bytes")

Supported SaveFormat Values

SaveFormatStatus
SaveFormat.PdfImplemented via ReportLab; raises ValueError if format handler not registered

Common Errors

ErrorCauseFix
ImportError: No module named 'reportlab'[pdf] extra not installedpip install "aspose-note[pdf]"
UnsupportedSaveFormatExceptionNon-PDF SaveFormat usedUse PDF format only
IncorrectPasswordExceptionEncrypted .one fileUse an unencrypted file
FileNotFoundErrorInput .one path wrongVerify path with Path.exists()
Permission error on outputOutput directory not writableCheck output directory permissions
 English