我需要使用C#代码(.NET 2.0)确定指定PDF文件中的页数. PDF文件将从文件系统中读取,而不是从URL读取.有没有人对如何做到这一点有任何指示?注意:将在执行此检查的PC上安装Adobe Acrobat R
iTextSharp示例
您必须安装iTextSharp.dll作为参考.从SourceForge.net下载iTextsharp这是一个使用控制台应用程序的完整工作程序.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
namespace GetPages_PDF
{
class Program
{
static void Main(string[] args)
{
// Right side of equation is location of YOUR pdf file
string ppath = "C:\\aworking\\Hawkins.pdf";
PdfReader pdfReader = new PdfReader(ppath);
int numberOfPages = pdfReader.NumberOfPages;
Console.WriteLine(numberOfPages);
Console.ReadLine();
}
}
}
