Programmatically Sorting Bookmarks In Bookmark Pane

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Programmatically Sorting Bookmarks In Bookmark Pane

Post by plgoldman »

First, I'm happy to say that we have secured a license - long demo/proof of concept cycle but the product got management approval. So, more questions.

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();
                }
Below is the bookmark list which appears in the bookmark pane after the above code runs on a test document:

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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Programmatically Sorting Bookmarks In Bookmark Pane

Post by Sasha - Tracker Dev Team »

Hello Paul,

To sort the bookmarks pane, you will have to recreate the whole bookmarks tree. To do that, for each bookmark parent recursively, you will have to make a sorted children array (IPXV_BookmList).
Then for this array, you will have to first call the op.bookmarks.delete operation and then add these children to the parent in the needed order. After that, you will need to call the op.bookmarks.addNew.simple operation, so that the UI will update the tree.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
plgoldman
User
Posts: 36
Joined: Fri Jan 05, 2018 8:36 pm

Re: Programmatically Sorting Bookmarks In Bookmark Pane

Post by plgoldman »

Hi Alex,

Your description of how to solve my bookmark sorting problem worked beautifully. Unfortunately I can't figure out how to insert a screen shot but the bookmark pane is now exactly what the end users are looking for. In particular now that everything is properly sorted I was able to do away with the "~Dup[n}" suffixes.

Thanks again,
Paul
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Programmatically Sorting Bookmarks In Bookmark Pane

Post by Sasha - Tracker Dev Team »

Glad to hear that Paul :)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply