当前位置: 代码迷 >> 综合 >> 文件流操作(6)——C#获取pdf文档的页数
  详细解决方案

文件流操作(6)——C#获取pdf文档的页数

热度:65   发布时间:2023-10-01 17:57:15.0

[操作pdf文档]之C#判断pdf文档的页数:

        /// <summary>/// 获取pdf文档的页数/// </summary>/// <param name="filePath"></param>/// <returns>-1表示文件不存在</returns>public static int GetPDFofPageCount(string filePath){int count = -1;//-1表示文件不存在if (File.Exists(filePath)){using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)){StreamReader reader = new StreamReader(fs);//从流的当前位置到末尾读取流string pdfText = reader.ReadToEnd();Regex rgx = new Regex(@"/Type\s*/Page[^s]");MatchCollection matches = rgx.Matches(pdfText);count = matches.Count;}}return count;}

 

  相关解决方案