检查要归档的 pdf 内容以查找 pdf 是否受密码保护

Check for pdf contents to file to find the pdf is password protected

我正在尝试查找 PDF 是否已加密。我在上传由我们的应用程序生成的文档时遇到问题。它适用于其他 PDF。

我发现发生这种情况是因为我的 PDF 文件包含加密元数据,即使我的文件没有密码保护。

trailer
<</Size 49
/Root 46 0 R
/Encrypt 47 0 R
/ID [<544779292784d1082d90221fd2118106><544779292784d1082d90221fd2118106>]
/Info 48 0 R
>>
startxref
218840
%%EOF


<<
/Filter/Standard
/R 3 /V 2 /Length 128
/O<0a9c59beafa2ba093c4bace402aae8e14eacb78a9ab178187f5922be0f044f63>
/U<a1b38ac6f6fe4d59b099045b71b52d7328bf4e5e4e758a4164004e56fffa0108>
/P -1852/EncryptMetadata true
>>

有人可以帮我看看我应该如何检查我的 PDF 文件是否只是加密元数据为真,而它没有密码保护。

您可以使用 Aspose.PDF for .NET API 区分加密和密码保护的 PDF 文件。 PdfFileInfo class 公开了一些 bool 属性,包括 IsEncrypted HasEditPasswordHasOpenPassword 可以检查它们以满足您的要求。以下是供您参考的代码片段:

        // Load source PDF file
        PdfFileInfo info = new PdfFileInfo();
        info.BindPdf(dataDir + "Test.pdf");
        if (info.IsEncrypted)
        {
            // Determine if the source PDF is encrypted
            Console.WriteLine("File is encrypted");
        }
        if (info.HasEditPassword)
        {
            // Determine if the source PDF has edit password
            Console.WriteLine("File has edit password");
        }
        if (info.HasOpenPassword)
        {
            // Determine if the source PDF has open password
            Console.WriteLine("File has open password");
        }

我们希望这会有所帮助。如果您需要任何进一步的帮助,请随时告诉我们。

PS:我作为开发人员在 Aspose 工作。