Säkra PDF Dokument
Contents
[
Hide
]
Ibland måste utvecklare arbeta med krypterade PDF-filer. De behöver till exempel säkra dokument med användar- och ägarlösenord så att inte vem som helst kan öppna dem, eller vill begränsa om dokumentinnehållet kan skrivas ut eller extraheras.
Den här artikeln förklarar hur du skickar in PDF säkerhetsalternativ när du sparar kalkylark till PDF.
Aspose.Cells tillhandahållerAspose.Cells.Rendering.PdfSecurity namnutrymme för att arbeta med säkerhet. Exempelkoden nedan beskriver hur du säkrar PDF-filer med 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); |
Om kalkylbladet innehåller formler är det bäst att ringaWorkbook.CalculateFormula()precis innan den renderas till PDF. Detta säkerställer att formelberoende värden beräknas om och att de korrekta värdena återges i PDF.