通过正则获得pdf页数

来源:互联网 发布:黑客攻防编程解析pdf 编辑:程序博客网 时间:2024/06/10 15:54

this.textBox1.Text = fbd.SelectedPath.ToString();
DirectoryInfo directory = new DirectoryInfo(this.textBox1.Text.Trim());
FileInfo fileitem = new FileInfo(directory.GetFiles()[0].FullName);
FileStream fs = File.OpenRead(fileitem.FullName);
StreamReader r = new StreamReader(fs);
string pdfText = r.ReadToEnd();
Regex rx1 = new Regex(@"/Type/s*/Page[^s]");//正则
MatchCollection matches = rx1.Matches(pdfText);
MessageBox.Show("The PDF file has " + matches.Count.ToString() + " page(s).");

原创粉丝点击