我使用AxAcroPdf来显示PDF文件,代码如下:
AcroPdfViewer.src = FilePath;
AcroPdfViewer.setPageMode("none");
AcroPdfViewer.setZoom(100);
AcroPdfViewer.setShowToolbar(true);如何在AxAcroPdf中获取文件的总页数?
发布于 2012-06-08 20:37:28
2018编辑:如下所述,原始答案引用的方法是not an AxAcroPdf method。但是一个被接受的答案不能被删除,所以我不得不把它留在这里。
发布于 2014-11-04 21:11:39
我认为执行pdf页面计数的最好方法是:
public static int GetNoOfPagesPDF(string FileName)
{
int result = 0;
FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
StreamReader r = new StreamReader(fs);
string pdfText = r.ReadToEnd();
System.Text.RegularExpressions.Regex regx = new Regex(@"/Type\s*/Page[^s]");
System.Text.RegularExpressions.MatchCollection matches = regx.Matches(pdfText);
result = matches.Count;
return result;
}希望它能有所帮助;)
来源:Counting PDF Pages
发布于 2016-03-29 14:25:28
如果您只安装了Acrobat Reader,则无法通过AxAcroPDFLib.AxAcroPDF获取页数。
对于第一个答案,使用GetNumPages()需要安装Acrobat SDK。此外,您需要有标准或专业的Adobe Acrobat Reader (不是免费的)才能使用此API。
就第二个答案而言,它在许多情况下都不起作用。并非所有的pdf文档都有"/Type /Page“标签。
但是您可以尝试使用其他API来获取PDF页面的数量。You can see this question.
https://stackoverflow.com/questions/10948022
复制相似问题