PDF 파일 복호화

비밀번호 또는 인증서로 암호화된 PDF 문서는 다른 작업을 수행하기 전에 잠금을 해제해야 합니다. 암호화된 PDF 문서에서 작업을 시도하면 예외가 발생합니다. 암호화된 PDF의 잠금을 해제한 후에는 하나 이상의 작업을 수행할 수 있습니다.

소유자 비밀번호를 사용하여 PDF 파일 복호화

PDF 파일을 복호화하려면 PdfFileSecurity 객체를 생성한 다음 DecryptFile 메서드를 호출해야 합니다. 또한 DecryptFile 메서드에 소유자 비밀번호를 전달해야 합니다. 다음 코드 스니펫은 PDF 파일을 복호화하는 방법을 보여줍니다.

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DecryptPDFFile()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
    
    using (var pdfFileInfo = new Aspose.Pdf.Facades.PdfFileInfo(dataDir + "sample_encrypted.pdf"))
    {
        if (pdfFileInfo.IsEncrypted)
        {
            using (var fileSecurity = new Aspose.Pdf.Facades.PdfFileSecurity())
            {
                // Bind PDF document
                fileSecurity.BindPdf(dataDir + "sample_encrypted.pdf");
                // Decrypt PDF document
                fileSecurity.DecryptFile("P@ssw0rd");
                // Save PDF document
                fileSecurity.Save(dataDir + "SampleDecrtypted_out.pdf");
            }
        }
    }
}