[英]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
類公開了一些bool屬性,包括IsEncrypted
HasEditPassword
和HasOpenPassword
,可以對其進行檢查以實現您的要求。 以下是供您參考的代碼段:
// 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一起擔任開發人員推廣人員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.