0

I have a code which extracts text from PDF documents, As such some PDFs are password protected, I need a way to Identify if a PDF is password protected

I am using.BitMiracle.Docotic.Pdf library.

Purpose:- If I find the PDF as password protected then I will show a dialog prompt to user to enter password and then open PDF using that password.

Edit 1: Solution posted as answer

Lucifer
  • 1,594
  • 2
  • 18
  • 32

1 Answers1

1

I found that IsPasswordProtected() method provided in library which returns a Boolean value if current specified file is password protected or not.

Solution:

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();                
        }
    }
}
Lucifer
  • 1,594
  • 2
  • 18
  • 32