如何在AxAcroPdf中获取pdf文件中的页数?

问题描述 投票:2回答:3

我使用AxAcroPdf显示PDF文件,代码如下:

AcroPdfViewer.src = FilePath;
AcroPdfViewer.setPageMode("none");
AcroPdfViewer.setZoom(100);
AcroPdfViewer.setShowToolbar(true);

如何在AxAcroPdf中获取PDF文件的总页数?

c# winforms axacropdf
3个回答
0
投票

2018编辑:如下所述,原始答案引用了not an AxAcroPdf method的方法。但是接受的答案不能删除,所以我必须把它留在这里。


1
投票

我认为执行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


0
投票

如果您只安装了Acrobat Reader,则无法通过AxAcroPDFLib.AxAcroPDF获取页数。

至于第一个答案,使用GetNumPages()要求您安装Acrobat SDK。此外,您需要使用标准或专业的Adobe Acrobat Reader(非免费)才能使用此API。

就第二个答案而言,它在许多情况下都不起作用。并非所有pdf文档都有“/ Type / Page”标记。

但您可以尝试使用其他API来获取PDF页面的数量。 You can see this question.

© www.soinside.com 2019 - 2024. All rights reserved.