[操作pdf文档]之C#判断pdf文档的页数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public static int GetPDFofPageCount(string filePath) { int count = -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; }
|
转自:https://blog.csdn.net/weixin_34037515/article/details/86193239