PDF 파사드

이 가이드는 org.aspose.pdf.facades 패키지의 작업 중심 파사드 클래스를 사용하는 방법을 보여줍니다. 각 파사드는 동일한 수명 주기를 따릅니다: bindPdf() → operations → save(). 주석을 평탄화하고, 북마크를 관리하고, 텍스트를 교체하고, 문서를 암호화하고, 텍스트를 추출하며, 페이지 번호를 추가하는 방법을 배우게 됩니다.

파사드 패턴

org.aspose.pdf.facades의 모든 파사드 클래스는 동일한 수명 주기를 따릅니다: bindPdf() → operations → save(). 파일 경로, 스트림 또는 Document 객체를 허용합니다.

PdfAnnotationEditor

문서 전체의 주석을 평탄화하거나 삭제하거나 개수를 셉니다. flattenAnnotations()은 모든 주석을 페이지 콘텐츠 스트림에 병합하여 영구적이고 편집할 수 없게 만듭니다:

try (PdfAnnotationEditor editor = new PdfAnnotationEditor()) {
    editor.bindPdf("input.pdf");
    editor.flattenAnnotations();
    editor.save("output.pdf");
}

deleteAnnotations(annotationType)은 이름으로 특정 주석 유형을 제거합니다.

PdfBookmarkEditor

PDF 개요 항목(북마크)을 생성하고 삭제합니다. deleteBookmarks()는 저장하기 전에 바인드된 문서에서 모든 개요 항목을 제거합니다:

try (PdfBookmarkEditor editor = new PdfBookmarkEditor()) {
    editor.bindPdf("input.pdf");
    editor.deleteBookmarks();
    editor.save("output.pdf");
}

PdfContentEditor

PDF 콘텐츠 스트림에서 전체 문서 또는 특정 페이지의 텍스트를 교체합니다. replaceText(searchString, replacement)는 일치하는 모든 텍스트 문자열을 찾아 교체합니다:

try (PdfContentEditor editor = new PdfContentEditor()) {
    editor.bindPdf("template.pdf");
    editor.replaceText("{{Name}}", "John Smith");
    editor.save("output.pdf");
}

PdfFileSecurity

문서를 AES-256로 암호화하고 DocumentPrivilege를 통해 접근 권한을 설정합니다. encryptFile(userPass, ownerPass, privilege, keySize)은 암호화를 적용하고 결과를 구성된 출력 파일에 기록합니다:

try (PdfFileSecurity security = new PdfFileSecurity("input.pdf", "out.pdf")) {
    DocumentPrivilege priv = DocumentPrivilege.getForbidAll();
    priv.setAllowPrint(true);
    security.encryptFile("user", "owner", priv, KeySize.x256);
}

PdfExtractor

PDF 문서에서 페이지별로 텍스트를 추출합니다. extractText()를 호출한 후, hasNextPageText()와 getNextPageText()를 사용하여 각 페이지의 추출된 내용을 반복합니다:

try (PdfExtractor extractor = new PdfExtractor()) {
    extractor.bindPdf("document.pdf");
    extractor.extractText();
    while (extractor.hasNextPageText()) {
        String text = extractor.getNextPageText();
        System.out.println(text);
    }
}

PdfFileStamp

PDF 페이지에 페이지 번호 스탬프를 addPageNumber(FormattedText)을 사용하여 추가합니다. 페이지 번호 레이블을 포함하는 FormattedText 인스턴스를 전달하십시오:

try (PdfFileStamp stamp = new PdfFileStamp("in.pdf", "out.pdf")) {
    stamp.addPageNumber(new FormattedText("Page #"));
    stamp.close();
}

addHeader(FormattedText, float) 또는 addFooter(FormattedText, float)을 사용하여 매 페이지 상단 또는 하단에서 지정된 여백에 반복 텍스트를 추가합니다.

참조

 한국어