2016-12-07 134 views
-1

我需要从PDF中提取文本。其中一些可以被密码保护。用Docotic.Pdf库打开密码保护PDF

如果PDF受密码保护,那么我想为用户提供一个对话框,以便他可以输入密码。

我该怎么做?

+0

感谢您的时间,但我发现了我要去这里不久后的解决方案 – Lucifer

回答

0

我已执行此代码,它完美的作品

BitMiracle.Docotic.Pdf.PdfDocument pdfcontent=null; 

public static string GetText(string filename) 
{ 
    if (PdfDocument.IsPasswordProtected(filename)) 
    { 
     //method to show dialog for password 
     pass=getPassword() 
     using (pdfcontent = new PdfDocument(filename, pass)) 
     { 
      return pdf.GetTextWithFormatting(); 
     } 
    } 
    else 
    { 
     using (pdfcontent = new PdfDocument(filename)) 
     {      
      return pdf.GetTextWithFormatting();     
     } 
    } 
}