您的位置:首页 > 编程语言 > C#

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

2014-01-23 19:46 495 查看
[操作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;
}


转载请注明出处。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: