How to check if a pdf page has a bookmark?

前端 未结 2 1458
执笔经年
执笔经年 2021-01-28 07:34

I\'m trying to check if a page in a pdf file has a bookmark and what is in that bookmark, I\'m using \"iTextSharp.text.pdf\" for reading and manipulating a pdf, but I can\'t fin

2条回答
  •  旧巷少年郎
    2021-01-28 08:27

    You can extract the page for each bookmark from the Page key in each bookmark dictionary.

    For example:

    public bool isBookmarked(string pdfSourceFile, int pageNumber)
    {
        var reader = new PdfReader(pdfSourceFile, new System.Text.ASCIIEncoding().GetBytes(""));
        var bookmarks = SimpleBookmark.GetBookmark(reader);
        foreach (var bookmark in bookmarks)
            if (Int32.Parse(bookmark["Page"].ToString().Split(' ')[0]) == pageNumber)
                return true;
    
        return false;
    }
    

提交回复
热议问题