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('PDF export 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, PdfSaveOptions, SaveFormat

opts = PdfSaveOptions(SaveFormat=SaveFormat.Pdf)

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

Tag Icon Rendering via PdfSaveOptions

PdfSaveOptions accepts tag icon display settings. Pass it instead of the bare SaveFormat enum when you need to customise tag icon rendering:

from aspose.note import Document, PdfSaveOptions, SaveFormat

doc = Document("TaggedNotes.one")

opts = PdfSaveOptions(SaveFormat.Pdf)
opts.TagIconDir = "./my-icons"
opts.TagIconSize = 12.0
opts.TagIconGap = 2.0

doc.Save("tagged.pdf", opts)

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


PdfSaveOptions Reference

PropertyTypeDefaultDescription
PageIndexint0Field exists but not forwarded to PDF exporter in v26.2 (has no effect)
PageCountint | NoneNoneField exists but not forwarded to PDF exporter in v26.2 (has no effect)
TagIconDirstr | NoneNonePath to directory containing custom NoteTag icon image files
TagIconSizefloat | NoneNoneRendered size of tag icons in points
TagIconGapfloat | NoneNonePadding around tag icons in points

Batch Export

Convert 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}  ({doc.Count()} pages)")
    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, PdfSaveOptions, SaveFormat

doc = Document("MyNotes.one")

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

Supported and Unsupported SaveFormat Values

SaveFormatStatus
SaveFormat.PdfImplemented
SaveFormat.OneRaises UnsupportedSaveFormatException
SaveFormat.HtmlRaises UnsupportedSaveFormatException
SaveFormat.JpegRaises UnsupportedSaveFormatException
SaveFormat.PngRaises UnsupportedSaveFormatException
SaveFormat.GifRaises UnsupportedSaveFormatException
SaveFormat.BmpRaises UnsupportedSaveFormatException
SaveFormat.TiffRaises UnsupportedSaveFormatException

Common Errors

ErrorCauseFix
ImportError: No module named 'reportlab'[pdf] extra not installedpip install "aspose-note[pdf]"
UnsupportedSaveFormatExceptionNon-PDF SaveFormat usedUse SaveFormat.Pdf 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