コード例 #1
0
        public static SelectInfo?GetSelection(this PdfBookmark bookmark,
                                              PdfDocument document)
        {
            PdfDestination destination = bookmark.Action?.Destination ?? bookmark.Destination;

            if (destination == null)
            {
                return(null);
            }

            int firstPage = destination.PageIndex;
            int lastPage  = document.Pages.Count - 1;

            PdfBookmark nextBookmark = bookmark.GetNextBookmark(document);

            if (nextBookmark != null)
            {
                PdfDestination nextDestination = nextBookmark.Action?.Destination ?? nextBookmark.Destination;

                lastPage = nextDestination.PageIndex - 1 > firstPage
          ? nextDestination.PageIndex - 1
          : firstPage;
            }

            return(new SelectInfo
            {
                StartPage = firstPage,
                EndPage = lastPage,
                StartIndex = 0,
                EndIndex = document.Pages[lastPage].Text.CountChars,
            });
        }
コード例 #2
0
        public static bool Contains(this PdfBookmark bookmark, PdfDocument document, int pageIdx)
        {
            PdfDestination destination = bookmark.Action?.GetDestination() ?? bookmark.Destination;

            if (destination == null)
            {
                return(false);
            }

            int            firstPage       = destination.PageIndex;
            PdfDestination nextDestination = null;

            while (nextDestination == null)
            {
                var nextBookmark = bookmark.GetNextBookmark(document);

                if (nextBookmark == null)
                {
                    return(pageIdx >= firstPage);
                }

                nextDestination = nextBookmark.Action?.GetDestination() ?? nextBookmark.Destination;
                bookmark        = nextBookmark;
            }

            int lastPage = nextDestination.PageIndex - 1 > firstPage
        ? nextDestination.PageIndex - 1
        : firstPage;

            return(pageIdx >= firstPage && pageIdx <= lastPage);
        }