首页 > 其他 > 详细

[开发笔记]-C#获取pdf文档的页数

时间:2014-01-24 07:35:42      阅读:384      评论:0      收藏:0      [点我收藏+]

 

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

bubuko.com,布布扣
        /// <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;
        }
bubuko.com,布布扣

 

转载请注明出处。

[开发笔记]-C#获取pdf文档的页数

原文:http://www.cnblogs.com/babycool/p/3531654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!