Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
PdfFileSecurity 클래스는 예외를 제어할 수 있게 해줍니다. 이를 위해 AllowExceptions 속성을 false 또는 true로 설정해야 합니다. 작업을 false로 설정하면 DecryptFile의 결과는 비밀번호의 정확성에 따라 true 또는 false를 반환합니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ControlExceptionPDFFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var fileSecurity = new Aspose.Pdf.Facades.PdfFileSecurity())
{
// Bind PDF document
fileSecurity.BindPdf(dataDir + "sample_encrypted.pdf");
// Disallow exceptions
fileSecurity.AllowExceptions = false;
// Decrypt PDF document
if (!fileSecurity.DecryptFile("IncorrectPassword"))
{
Console.WriteLine("Something wrong...");
Console.WriteLine($"Last exception: {fileSecurity.LastException.Message}");
}
// Save PDF document
fileSecurity.Save(dataDir + "SampleDecrtypted_out.pdf");
}
}
AllowExceptions 속성을 true로 설정하면 try-catch 연산자를 사용하여 작업의 결과를 얻을 수 있습니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ControlExceptionPDFFile2()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
using (var fileSecurity = new Aspose.Pdf.Facades.PdfFileSecurity())
{
// Bind PDF document
fileSecurity.BindPdf(dataDir + "sample_encrypted.pdf");
// Allow exceptions
fileSecurity.AllowExceptions = true;
try
{
// Decrypt PDF document
fileSecurity.DecryptFile("IncorrectPassword");
}
catch (Exception ex)
{
Console.WriteLine("Something wrong...");
Console.WriteLine($"Exception: {ex.Message}");
}
// Save PDF document
fileSecurity.Save(dataDir + "SampleDecrtypted_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.