op.search - clear highlight

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
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

op.search - clear highlight

Post by jusWest »

We har using op.search to search and highlight with PageSearchCallBack as described elsewhere on this forum. And this works well.

I'm curious to know if there is a function or way to easily clear the higlightet words, so they apperar normal again.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: op.search - clear highlight

Post by Sasha - Tracker Dev Team »

Hello jusWest,

Can you give a code snippet on how you are adding the highlights?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: op.search - clear highlight

Post by jusWest »

this is the code:

Code: Select all

        public void HighlightWordsInPage(uint pageNum, List<string> wordlist)
        {
            try
            {
                int nID = _Inst.Str2ID("op.search", false);
                IOperation Op = _Inst.CreateOp(nID);
                ICabNode input = Op.Params.Root["Input"];
                input.Add().v = _Doc.CoreDoc;

                ICabNode options = Op.Params.Root["Options"];

                if (wordlist != null)
                {
                    foreach (var word in wordlist)
                    {
                        options["OR"].Add().v = word;
                    }
                }

                options["StartPage"].v = pageNum-1;
                options["StopPage"].v = pageNum-1;
                options["Proximity"].v = PXV_SearchProximity.PXV_SearchProximity_SamePage;
                
                PageSearchCallBack clb = new PageSearchCallBack(_Inst);
                options["Callback"].v = clb;

                options["Flags"].v = (int)PXV_SearchFlags.PXV_SearchFlag_GetTextQuads | (int)PXV_SearchFlags.PXV_SearchFlag_IncludePageText
                                    | (int)PXV_SearchFlags.PXV_SearchFlag_IncludeBookmarks | (int)PXV_SearchFlags.PXV_SearchFlag_IncludeAnnotations
                                    | (int)PXV_SearchFlags.PXV_SearchFlag_IncludeFormFields;

                Op.Do();

            }
            catch (Exception ex)
            {
                HasError = true;
                ErrorMessage = ex.Message;
                AppLogger.Error("HighlightWordsInPage - " + ex.Message);
            }
        }
Here is the OnNewEvent in the PageSearchCallbak:

Code: Select all

        public void OnNewEntry(IPXV_SearchEntry pEntry)
        {
            //Highlighting items in the document
            uint i = 0;
            IPXC_Document doc = null;
            IPXV_Document vDoc = null;
            IPXC_Page page = null;
            IPXV_DocHighlighter highlighter = null;
            while (i < pEntry.Count)
            {
                IPXV_SearchEntryItem item = pEntry[i];
                IPXV_SearchPtr ptr = item.Ptr;
                for (uint j = 0; j < ptr.Count; j++)
                {
                    PXV_SearchPtrChunk chunk = ptr[j];
                    //First we get the document
                    if (chunk.nType == (uint)PXV_SearchPtrChunkType.PXV_SearchPtrChunk_Document)
                    {
                        doc = ptr.Doc[chunk.nValue];
                        vDoc = m_Inst.FindDocByCoreDoc(doc);
                        //Now we'll need to check whether the document is opened so that we can highlight it
                        if (vDoc != null)
                        {
                            highlighter = vDoc.AddNewHighlighter(PXV_DocHighlightType.PXV_DocHighlight_Page);
                        }
                    }
                    else if (chunk.nType == (uint)PXV_SearchPtrChunkType.PXV_SearchPtrChunk_Page)
                    {
                        if (doc != null)
                            page = doc.Pages[chunk.nValue];
                        if (page != null)
                        {
                            //Now we have the page where the text is found
                            for (uint k = 0; k < item.TextRangesCount; k++)
                            {
                                //Now we need to get the coordinates of the highlight boxes
                                IPXC_QuadsF quads = item.GetTextRangeQuads(k);
                                //Highlighting the search results
                                if (highlighter != null)
                                {
                                    PXV_DocHighlightAdvanced ha = new PDFXEdit.PXV_DocHighlightAdvanced();
                                    highlighter.Add(page, quads, null, null, ref ha, 0);
                                    //Setting the current page of the document to the one with the results
                                    vDoc.ActiveView.PagesView.Layout.CurrentPage = page.Number;
                                }
                            }
                        }

                    }
                }
                i++;
            }
        }
jusWest
User
Posts: 150
Joined: Fri Aug 24, 2018 8:26 am

Re: op.search - clear highlight

Post by jusWest »

any help?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: op.search - clear highlight

Post by Sasha - Tracker Dev Team »

Hello jusWest,

If you have the highlighter interface, then you can use the IPXV_Document::RemoveHighlighter to remove it from the document just how you have added it.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply