安全な PDF ドキュメント
Contents
[
Hide
]
場合によっては、開発者は暗号化された PDF ファイルを操作する必要があります。たとえば、ユーザーと所有者のパスワードを使用してドキュメントを保護し、誰もがドキュメントを開くことができないようにしたり、ドキュメントの内容を印刷または抽出できるように制限したりする必要があります。
この記事では、スプレッドシートを PDF に保存するときに PDF セキュリティ オプションを渡す方法について説明します。
Aspose.Cells はAspose.Cells.Rendering.PdfSecurityセキュリティを扱うための名前空間。以下のサンプル コードは、PDF を Aspose.Cells で保護する方法を示しています。
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "input.xlsx"); | |
// Instantiate PDFSaveOptions to manage security attributes | |
PdfSaveOptions saveOption = new PdfSaveOptions(); | |
saveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions(); | |
// Set the user password | |
saveOption.SecurityOptions.UserPassword = "user"; | |
// Set the owner password | |
saveOption.SecurityOptions.OwnerPassword = "owner"; | |
// Disable extracting content permission | |
saveOption.SecurityOptions.ExtractContentPermission = false; | |
// Disable print permission | |
saveOption.SecurityOptions.PrintPermission = false; | |
// Save the PDF document with encrypted settings | |
workbook.Save(dataDir+ "securepdf_test.out.pdf", saveOption); |
スプレッドシートに数式が含まれている場合は、Workbook.CalculateFormula()これにより、式に依存する値が再計算され、正しい値が PDF にレンダリングされます。