PDF エクスポート — Aspose.Note FOSS for Python
Aspose.Note FOSS for Python supports exporting loaded .one ドキュメントを PDF に変換するには Document.Save(). PDF のレンダリングはオプションの ReportLab ライブラリです。現在実装されている唯一の保存形式です。他の SaveFormat 値はエラーを発生させます UnsupportedSaveFormatException.
前提条件
ライブラリは次の方法でインストールします [pdf] 余分なオプションで ReportLab を取得します:
pip install "aspose-note[pdf]"検証:
python -c "from aspose.note import Document, SaveFormat; print('PDF export ready')"基本エクスポート
ドキュメントのすべてのページを単一の PDF ファイルにエクスポートします:
from aspose.note import Document, SaveFormat
doc = Document("MyNotes.one")
doc.Save("output.pdf", SaveFormat.Pdf)ページは PDF 内で DOM に現れる順序と同じ順序で表示されます。.
PdfSaveOptions の使用
PdfSaveOptions はエクスポートに対する細かな制御を提供します。裸のものの代わりにそれを渡してください SaveFormat 列挙型:
from aspose.note import Document
from aspose.note.saving import PdfSaveOptions
opts = PdfSaveOptions()
doc = Document("MyNotes.one")
doc.Save("output.pdf", opts)注意: PageIndex / PageCount: これらのフィールドは次に存在します PdfSaveOptions ただし、 v26.3.1 の PDF エクスポーターに転送されません 影響を与えません。ドキュメント全体が常にエクスポートされます。.
PdfSaveOptions リファレンス
| プロパティ | タイプ | デフォルト | 説明 |
|---|---|---|---|
PageIndex | int | 0 | フィールドは存在しますが v26.3.1 の PDF エクスポーターに転送されません (効果がありません) |
PageCount | `int | None` | None |
バッチエクスポート
すべてを変換 .one ディレクトリ内のファイルを 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}")ストリームからロードし、ファイルに保存
ストリームベースのロードとファイルベースの PDF 出力を組み合わせます:
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)メモリ内で PDF バイト列を取得
Document.Save() バイナリストリームを直接受け取ります: 一時ファイルは不要です:
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")サポートされている SaveFormat の値
| SaveFormat | ステータス |
|---|---|
SaveFormat.Pdf | 実装済み |
一般的なエラー
| エラー | 原因 | 修正 |
|---|---|---|
ImportError: No module named 'reportlab' | [pdf] extra がインストールされていません | pip install "aspose-note[pdf]" |
UnsupportedSaveFormatException | PDF 以外の SaveFormat が使用されました | 使用 SaveFormat.Pdf のみ |
IncorrectPasswordException | 暗号化された .one ファイル | 暗号化されていないファイルを使用 |
FileNotFoundError | 入力 .one パスが間違っています | パスを検証 Path.exists() |
| 出力で権限エラー | 出力ディレクトリが書き込み不可 | 出力ディレクトリの権限を確認 |