Python에서 OneNote 파일을 PDF로 내보내는 방법
Aspose.Note FOSS for Python enables programmatic PDF export of Microsoft OneNote .one Microsoft Office 또는 운영 체제 수준의 문서 변환기를 필요로하지 않은 섹션 파일. Document.Save() 선택적 방법에 의해 지원되는 방법 ReportLab PDF 렌더링.
혜택
- 서버 친화적: 헤드없는 Linux 서버 및 CI/CD 컨테이너를 포함하여 모든 OS에서 실행됩니다.
- 흐름 가능성: 저장 직접 에 대 한
io.BytesIO뷔페, 일시적인 파일이 필요하지 않습니다. - 무료 및 오픈소스:■ MIT 라이센스
원칙들
PDF 수출은 선택적 ReportLab 의존성을 필요로합니다. [pdf] 추가 :
pip install aspose-note만약 당신이 이미 가지고 있다면 aspose-note 추가 없이 설치:
pip install --upgrade "aspose-note[pdf]"ReportLab가 사용할 수 있는지 확인하십시오 :
python -c "import reportlab; print(reportlab.Version)"단계별 가이드
단계 1: PDF 지원을 사용하여 aspose-note를 설치합니다.
pip install aspose-note설치 확인 (PDF는 수출 단지 형식입니다 - 도서관은 OneNote 출처 파일에서 PDF 출력을 생성합니다; 반대 방향이 지원되지 않습니다):
from aspose.note import Document, SaveFormat
print("aspose-note is ready.")단계 2: OneNote 파일을 다운로드합니다.
from aspose.note import Document
doc = Document("MyNotes.one")단계 3: 전체 문서를 PDF로 내보내십시오.
가장 간단한 수출, 기본 설정으로 모든 페이지를 다루는:
from aspose.note import Document, SaveFormat
doc = Document("MyNotes.one")
doc.Save("output.pdf", SaveFormat.Pdf)
print("PDF saved to output.pdf")단계 4 : PdfSaveOptions 사용하기
PdfSaveOptions PDF 수출 설정을 구성하십시오 :
from aspose.note import Document
from aspose.note.saving import PdfSaveOptions
doc = Document("MyNotes.one")
opts = PdfSaveOptions()
doc.Save("output.pdf", opts)사용 가능한 PdfSaveOptions
| 옵션 | 유형 | 가상화 | 설명 |
|---|---|---|---|
PageIndex | int | 0 | 제로 기반 인덱스 첫 페이지를 수출 (0 = 첫 번째 페이지) |
PageCount | `int | None` | None |
5단계: 메모리 스트림으로 수출
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")단계 6 : 배치 수출 다중 파일
다중 과정 .one 디렉토리에 있는 파일:
from pathlib import Path
from aspose.note import Document, SaveFormat
input_dir = Path("./onenote_files")
output_dir = Path("./pdf_output")
output_dir.mkdir(exist_ok=True)
for one_file in input_dir.glob("*.one"):
doc = Document(str(one_file))
out_path = output_dir / one_file.with_suffix(".pdf").name
doc.Save(str(out_path), SaveFormat.Pdf)
print(f"Exported: {one_file.name} -> {out_path.name}")일반적인 문제와 해결책
1. ImportError: No module named ‘reportlab’
원인은: 그 쪽 [pdf] 추가 설치되지 않았습니다.
고정:
pip install aspose-note2. UnsupportedSaveFormatException
원인은: 다른 형식으로 다른 SaveFormat.Pdf 사용되었는데, 그냥 SaveFormat.Pdf 실행되고 있다.
고정:항상 사용하기 SaveFormat.Pdf 다른 형식은 API 호환성에 대해 선언되지만 업그레이드합니다. UnsupportedSaveFormatException.
3. IncorrectPasswordException
원인은: 그 쪽 .one 파일이 암호화되어 있습니다. 암시된 문서가 지원되지 않습니다.
고정: 암호화되지 않은 사용자 .one 상업적인 Aspose.Note 제품은 암호화를 지원합니다.
4. FileNotFoundError
원인은: 입장에 대한 .one 파일 경로는 잘못된 것입니다.
고정:사용하기 : 사용 pathlib.Path.exists() 충전하기 전에 확인해야 할 사항:
from pathlib import Path
from aspose.note import Document, SaveFormat
path = Path("MyNotes.one")
assert path.exists(), f"File not found: {path.resolve()}"
doc = Document(str(path))
doc.Save("output.pdf", SaveFormat.Pdf)5. Output PDF is blank or empty
원인은: 그 쪽 .one 파일에는 페이지가 있지만 텍스트 콘텐츠가 없습니다 (텍스팅이 없는 이미지 또는 테이블 만 포함되어 있습니다). PDF renderer는 ReportLab가 DOM에서 무엇을 할 수 있는지에 따라 페이지를 생성합니다.
고정: 수출하기 전에 페이지 콘텐츠를 확인하십시오 :
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
text_count = len(doc.GetChildNodes(RichText))
print(f"RichText nodes found: {text_count}")자주 묻는 질문들
어떤 저장 형식이 지원되는가?
단지 SaveFormat.Pdf 현재 진행 중인데요~ 이건 SaveFormat Enum은 정확히 한 명의 회원이 있습니다 : SaveFormat.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()수출은 페이지 주문을 유지합니까?
예. 페이지는 DOM에 나타나는 동일한 순서로 수출됩니다 (주문을 이터링하여 반환되는 주문) Document).
PDF 수출은 Linux에서 사용할 수 있습니까?
예. ReportLab 및 Aspose.Note FOSS for Python 모두 OS 독립적입니다.
페이지의 하위 세트를 수출 할 수 있습니까?
사용하기 예 PdfSaveOptions 와 함께 PageIndex (제로 기반의 시작 페이지) 및 PageCount (출출할 페이지의 수); None = 모든 남은) 페이지의 하위 세트를 수출합니다. 두 필드는 v26.3.2에서 PDF 수입자에게 전송됩니다.
관련 자원 :