PDF 내보내기 — Aspose.Note FOSS for Python
Aspose.Note FOSS for Python supports exporting loaded .one 문서를 PDF로 변환 via Document.Save(). PDF 렌더링은 선택적 ReportLab 라이브러리. 현재 구현된 유일한 저장 형식이며; 다른 SaveFormat 값은 오류를 발생시킵니다 UnsupportedSaveFormatException.
전제 조건
다음 옵션으로 라이브러리를 설치합니다 [pdf] extra를 사용하여 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)페이지는 DOM에 나타나는 순서와 동일한 순서로 PDF에 표시됩니다.
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() |
| 출력에 권한 오류 | 출력 디렉터리를 쓸 수 없습니다 | 출력 디렉터리 권한을 확인하십시오 |