I have some LINQ code that extracts bookmarks from PDFs that match a certain naming convention (using Aspose.Pdf):
IOrderedEnumerable<Bookmark> magicBookmarks = (
from bookmark in allBookmarks.AsEnumerable()
where bookmark.Title.StartsWith(MAGIC_PHRASE)
// ... other criteria
orderby bookmark.PageNumber ascending
select bookmark
);
The Bookmark class has a property called PageNumber that gets the page number where a bookmark starts. In my situation, a bookmark can represent a section of 1…n pages.
What I’d like to do is transform this sequence into another sequence of Tuple<int, int> (or some comparable “pair” structure) where Item1 of each pair equals the PageNumber value of the corresponding element in the source sequence and Item2 equals the `PageNumber’ value of the next element in the source sequence minus 1 (for the sake of this exercise, assume that all Bookmarks in the source sequence occur in succession in the document from which they were extracted).
In short, I want the end result to be a sequence of pairs that represent the start and end pages of each bookmarked PDF section.
You could use
Enumerable.Zipfor this by zipping the enumeration with itself just skipping the first element: