C# 获取安全PDF中的页面计数

C# 获取安全PDF中的页面计数,c#,C#,我创建了一个C#应用程序,使用下面的编码来获得pdf页面计数 public static int GetNoOfPagesPDF(string FileName) { int result = 0; FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); StreamReader r = new StreamReade

我创建了一个C#应用程序,使用下面的编码来获得pdf页面计数

public static int GetNoOfPagesPDF(string FileName)
        {
            int result = 0;
            FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            StreamReader r = new StreamReader(fs);
            string pdfText = r.ReadToEnd();

            System.Text.RegularExpressions.Regex regx = new Regex(@"/Type\s*/Page[^s]");
            System.Text.RegularExpressions.MatchCollection matches = regx.Matches(pdfText);
            result = matches.Count;
            return result;

        }

但我无法在受保护的PDF中获取页面计数。在这种情况下,我如何获得页面计数。

好吧,我不知道没有第三部分库,但是有类和属性,如何才能找到页面计数

public int getNumberOfPages()
Gets the number of pages in the document.
Returns:
the number of pages in the document
这是一个例子

string path = @"C:\Users\Soner\Desktop\eBook\C#\sample.pdf";
PdfReader reader = new PdfReader(path);
int number = reader.NumberOfPages;

我使用PdfSharp.dll作为第三部分库。但问题是它不适用于受保护的PDF。