【问题标题】:How can I get number of pages in a pdf file in AxAcroPdf?如何在 AxAcroPdf 中获取 pdf 文件的页数?
【发布时间】:2012-06-12 11:08:40
【问题描述】:

我使用 AxAcroPdf 显示带有此代码的 PDF 文件:

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

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

【问题讨论】:

    标签: c# winforms axacropdf


    【解决方案1】:

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

    【讨论】:

    • 我允许的函数是:GetVersions、GetType、GetPreferredSize、GetOcx、GetNextControl、GetLifetimeService、GetHashCode、GetContainerControl、GetChildAtPoint。我无法访问 GetNumPages ! , 我该如何使用它?
    • 您正在查看 ActiveX 主机控件上的方法 - 使用 GetOcx() 获取对 AxAcroPdf 控件的引用。
    • 它似乎不是 AxAcroPdf 类的一部分。根据文档,它是 PDDoc 类的一部分。我遇到了与 ahmadi 相同的问题,它没有显示为可用方法...
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

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

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

      【讨论】:

        猜你喜欢
        • 2010-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        相关资源
        最近更新 更多