セキュアなPDFドキュメント
Contents
[
Hide
]
開発者は、暗号化されたPDFファイルと作業する必要がある場合があります。
- ドキュメントをオーナーパスワードとユーザーパスワードでセキュリティ保護して、誰もがそれを開けなくする。
- ドキュメントを開いた後にドキュメントに制限や権限を設定します。例: ドキュメントの内容を印刷または抽出できるかどうかを制限します。
この記事では、スプレッドシートをPDFに保存する際にPDFセキュリティオプションを渡す方法について説明します。
Aspose.Cells for Python via .NETはPdfSecurityOptionsを提供します。セキュリティでの作業に役立ちます。PDFに保存する際にオーナーパスワードとユーザーパスワードを設定できます。暗号化されたPDF文書を表示するためには、オーナーパスワードまたはユーザーパスワードが必要になります。
- ユーザーパスワードはnullまたは空の文字列にすることができます。この場合、ユーザーがPDFドキュメントを開く際にパスワードが要求されません。
- 正しい所有者パスワードでPDFドキュメントを開くと、ドキュメントへのフルアクセス(指定されたアクセス制限なし)が可能です。
- 正しいユーザーパスワードでPDFドキュメントを開く(またはユーザーパスワードのないドキュメントを開く)と、指定された権限に応じて限定されたアクセスが可能です。
以下のサンプルコードでは、Aspose.Cells for Python via .NETを使用してPDFをセキュリティで保護する方法が説明されています。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import PdfSaveOptions, Workbook | |
from aspose.cells.rendering.pdfsecurity import PdfSecurityOptions | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open an Excel file | |
workbook = Workbook(dataDir + "input.xlsx") | |
# Instantiate PDFSaveOptions to manage security attributes | |
saveOption = PdfSaveOptions() | |
saveOption.security_options = PdfSecurityOptions() | |
# Set the user password | |
saveOption.security_options.user_password = "user" | |
# Set the owner password | |
saveOption.security_options.owner_password = "owner" | |
# Disable extracting content permission | |
saveOption.security_options.extract_content_permission = False | |
# Disable print permission | |
saveOption.security_options.print_permission = False | |
# Save the PDF document with encrypted settings | |
workbook.save(dataDir + "securepdf_test.out.pdf", saveOption) |
スプレッドシートに数式が含まれている場合、スプレッドシートをPDFにレンダリングする直前にWorkbook.calculate_formula()を呼び出すことが最善です。これにより、数式に依存した値が再計算され、正しい値がPDFに表示されます。