In my application I have a need to detect duplicate bookmarks and present them to the end user for editing. I have created the following code to build a bookmark list, sort it by title and then edit the title of the duplicates with a suffix of the form "~Dup[n]" where "n" is the index of the duplicate in question - if I have three sets of duplicate bookmarks, e.g. bookmarks "abc," "def," and "ghi" then their titles will be changed to "abc~Dup1" where "abc" was the first detected duplicate, "def~Dup2" where "def" was the second detected duplicate and so on.
Code: Select all
bookMarkList1 = new List<PDFXEdit.IPXC_Bookmark>();
PDFXEdit.IPXC_Document doc = pdfCtl.Doc.CoreDoc;
PDFXEdit.IPXC_Bookmark bookMarks = doc.BookmarkRoot;
if (bookMarks.ChildrenCount > 0)
{
PDFXEdit.IPXC_Bookmark bookMark1 = bookMarks.FirstChild;
if (bookMark1 != null)
{
bookMarkList1.Add(bookMark1);
for (uint i = 0; i < bookMarks.ChildrenCount - 1; i++)
{
bookMark1 = bookMark1.Next;
bookMarkList1.Add(bookMark1);
}
}
}
List<PDFXEdit.IPXC_Bookmark> bookMarkListSorted = bookMarkList1.OrderBy(a => a.Title).ToList();
PDFXEdit.IPXC_Bookmark currBkMk = null;
bool matchFound = false;
bool oneMatchFound = false;
int dupCount = 1;
for (int i = 0; i < bookMarkListSorted.Count; i++)
{
if (i == 0)
{
currBkMk = bookMarkListSorted[i];
}
else
{
if (currBkMk.Title == bookMarkListSorted[i].Title)
{
bookMarkListSorted[i].Title = bookMarkListSorted[i].Title + "~Dup" + dupCount.ToString();
matchFound = true;
oneMatchFound = true;
}
else
{
if (matchFound)
{
currBkMk.Title = currBkMk.Title + "~Dup" + dupCount.ToString();
dupCount++;
}
currBkMk = bookMarkListSorted[i];
matchFound = false;
}
}
}
if (matchFound)
{
currBkMk.Title = currBkMk.Title + "~Dup" + dupCount.ToString();
}
03-27-2018#medical
04-04-2018#medical
03-27-2018#laboratory
03-27-2018#request~Dup2
03-27-2018#operative~Dup1
03-27-2018#request~Dup2
03-27-2018#operative~Dup1
03-27-2018#operative~Dup1
03-07-2018#pathology and biopsy
Is there a way to sort the bookmark pane contents so that the above bookmarks would appear in order by title? The idea is to have all duplicates be contiguous. As always, your help is appreciated.
Regards,
Paul