PDF Facades Đánh giá

Hướng dẫn này cho thấy cách sử dụng các lớp facade tập trung vào nhiệm vụ trong org.aspose.pdf.facades Mỗi mặt hàng theo cùng một vòng đời: bindPdf() Các hoạt động → save().Bạn sẽ học cách làm những ghi chú, quản lý các dấu sách, thay thế văn bản, mã hóa tài liệu, rút văn Bản và thêm số trang.

Hình mẫu Facade

Tất cả các lớp học trong org.aspose.pdf.facades theo cùng một vòng đời: bindPdf() Các hoạt động → save().Họ chấp nhận các đường file, dòng hoặc Document đối tượng .

PdfĐiều kiệnEditor

Tải, xóa hoặc tính toán các ghi chú trên toàn bộ tài liệu. flattenAnnotations() kết hợp tất cả các ghi chú vào dòng nội dung trang, làm cho chúng vĩnh viễn và không chỉnh sửa:

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

deleteAnnotations(annotationType) loại bỏ một kiểu ghi chú cụ thể theo tên.

PdfBookMáy tính

Tạo và xóa các bản nhập PDF outline (bookmarks). deleteBookmarks() xóa tất cả các bản ghi từ tài liệu được gắn kết trước khi tiết kiệm:

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

PdfContentThông tin

Thay thế văn bản trong nội dung PDF dòng trên toàn bộ tài liệu hoặc trên một trang cụ thể. replaceText(searchString, replacement) Tìm và thay thế tất cả các dòng văn bản phù hợp:

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

PdfFileĐiểm bảo mật

Crypto tài liệu với AES-256 và thiết lập quyền truy cập thông qua DocumentPrivilege. encryptFile(userPass, ownerPass, privilege, keySize) Sử dụng mã hóa và viết kết quả cho tệp xuất bản được cấu hình:

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

PdfThuyết minh

Thích xuất trang văn bản theo trang từ tài liệu PDF. sau khi gọi extractText(), sử dụng hasNextPageText()getNextPageText() để iterate nội dung thu được của mỗi trang:

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

PdfFileĐiểm nhấn

Thêm số trang vào các trang PDF bằng cách sử dụng addPageNumber(FormattedText).Đã qua A FormattedText Ví dụ chứa nhãn số trang:

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

Sử dụng addHeader(FormattedText, float) hoặc addFooter(FormattedText, float) để thêm lặp lại văn bản ở một ranh giới cụ thể từ trên hoặc dưới cùng của mỗi trang.

See Also

 Tiếng Việt