Aspose.pdf 如何获取书签的对应页号,感谢技术人员为小弟解答。


#1

源文件:pdflj.pdf (7.8 MB)

两个小问题,谢谢技术大哥帮忙解答:

1,如何获得书签对应的页号。

2,如何获得第二个书签以后所有书签和页号,不获取第一个书签和页号。

如下代码复制就可以用:

       //获得书签
        List<string> list2 = new List<string>();
        //获得书签所对应的页号
        List<int> sz = new List<int>();

        Aspose.Pdf.Document document = new Aspose.Pdf.Document(pdflj);
        // Create PdfBookmarkEditor
        PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
        // Open PDF file
        bookmarkEditor.BindPdf(document);

        // Extract bookmarks
        Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();

        foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
        {
            String shuqian = bookmark.Title;

            list2.Add(shuqian);
        }

#2

@fhn123456

感谢您与支持人员联系。

您可以访问获取书签页码并根据您的要求修改代码段。 我们分享了以下可能的方法之一:

// Create PdfBookmarkEditor
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkEditor.BindPdf(dataDir + "pdflj.pdf");
// Extract bookmarks
Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();
int skipIteration = 1;
int iteration = 0;
foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
{
    iteration++;
    if (iteration == skipIteration)
    {
        continue;
    }
    string strLevelSeprator = string.Empty;
    for (int i = 1; i < bookmark.Level; i++)
    {
        strLevelSeprator += "----";
    }
    Console.WriteLine("{0}Page Number: {1}", strLevelSeprator, bookmark.PageNumber);
}

#3

谢谢,完美的解决了我的问题