op.search
From PDF XChange PDF SDK
(→Sample) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 30: | Line 30: | ||
public class SearchCallback : PDFXEdit.IPXV_SearchCallback | public class SearchCallback : PDFXEdit.IPXV_SearchCallback | ||
{ | { | ||
+ | PDFXEdit.IPXV_Inst m_Inst = null; | ||
+ | |||
+ | public SearchCallback(PDFXEdit.IPXV_Inst Inst) | ||
+ | { | ||
+ | m_Inst = Inst; | ||
+ | } | ||
public void OnFinish(int nResCode) | public void OnFinish(int nResCode) | ||
{ | { | ||
Line 37: | Line 43: | ||
public void OnNewEntry(PDFXEdit.IPXV_SearchEntry pEntry) | public void OnNewEntry(PDFXEdit.IPXV_SearchEntry pEntry) | ||
{ | { | ||
− | + | //Highlighting items in the document | |
+ | uint i = 0; | ||
+ | PDFXEdit.IPXC_Document doc = null; | ||
+ | PDFXEdit.IPXV_Document vDoc = null; | ||
+ | PDFXEdit.IPXC_Page page = null; | ||
+ | PDFXEdit.IPXV_DocHighlighter highlighter = null; | ||
+ | while (i < pEntry.Count) | ||
{ | { | ||
PDFXEdit.IPXV_SearchEntryItem item = pEntry[i]; | PDFXEdit.IPXV_SearchEntryItem item = pEntry[i]; | ||
− | + | PDFXEdit.IPXV_SearchPtr ptr = item.Ptr; | |
+ | for (uint j = 0; j < ptr.Count; j++) | ||
{ | { | ||
− | // | + | PDFXEdit.PXV_SearchPtrChunk chunk = ptr[j]; |
− | // | + | //First we get the document |
+ | if (chunk.nType == (uint)PDFXEdit.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(PDFXEdit.PXV_DocHighlightType.PXV_DocHighlight_Page); | ||
+ | } | ||
+ | } | ||
+ | else if (chunk.nType == (uint)PDFXEdit.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 | ||
+ | PDFXEdit.IPXC_QuadsF quads = item.GetTextRangeQuads(k); | ||
+ | //Highlighting the search results | ||
+ | if (highlighter != null) | ||
+ | { | ||
+ | PDFXEdit.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++; | ||
} | } | ||
} | } | ||
Line 74: | Line 121: | ||
options["AND"].Add().v = "is"; | options["AND"].Add().v = "is"; | ||
options["AND"].Add().v = "defined"; | options["AND"].Add().v = "defined"; | ||
− | SearchCallback clbk = new SearchCallback(); | + | SearchCallback clbk = new SearchCallback(pdfCtl.Inst); |
options["Callback"].v = clbk; | options["Callback"].v = clbk; | ||
+ | options["Flags"].v = (int)PDFXEdit.PXV_SearchFlags.PXV_SearchFlag_GetTextQuads | (int)PDFXEdit.PXV_SearchFlags.PXV_SearchFlag_IncludePageText; | ||
Op.Do(); | Op.Do(); | ||
} | } |
Latest revision as of 02:00, 30 January 2017
Overview
The operation allows searching for words/phrases in the given folder or document(s).
Parameters
Name | Type | Description |
---|---|---|
Input | Array | Array of IUnknown -based objects containing either a folder with documents that will be searched through or documents that will be used for words/phrases search.
|
Output | Array | Not used. |
Options | Dictionary | Dictionary with options of the operation. |
Sample
//C# public class SearchCallback : PDFXEdit.IPXV_SearchCallback { PDFXEdit.IPXV_Inst m_Inst = null; public SearchCallback(PDFXEdit.IPXV_Inst Inst) { m_Inst = Inst; } public void OnFinish(int nResCode) { } public void OnNewEntry(PDFXEdit.IPXV_SearchEntry pEntry) { //Highlighting items in the document uint i = 0; PDFXEdit.IPXC_Document doc = null; PDFXEdit.IPXV_Document vDoc = null; PDFXEdit.IPXC_Page page = null; PDFXEdit.IPXV_DocHighlighter highlighter = null; while (i < pEntry.Count) { PDFXEdit.IPXV_SearchEntryItem item = pEntry[i]; PDFXEdit.IPXV_SearchPtr ptr = item.Ptr; for (uint j = 0; j < ptr.Count; j++) { PDFXEdit.PXV_SearchPtrChunk chunk = ptr[j]; //First we get the document if (chunk.nType == (uint)PDFXEdit.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(PDFXEdit.PXV_DocHighlightType.PXV_DocHighlight_Page); } } else if (chunk.nType == (uint)PDFXEdit.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 PDFXEdit.IPXC_QuadsF quads = item.GetTextRangeQuads(k); //Highlighting the search results if (highlighter != null) { PDFXEdit.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++; } } public void OnStart() { } public void OnStartPtr(PDFXEdit.IPXV_SearchPtr pPtr) { } public void OnStopPtr(PDFXEdit.IPXV_SearchPtr pPtr, bool bIncomplete) { } } private void SearchOperation(PDFXEdit.IPXV_Document Doc, PDFXEdit.PXV_Inst Inst) { int nID = Inst.Str2ID("op.search", false); PDFXEdit.IOperation Op = Inst.CreateOp(nID); PDFXEdit.ICabNode input = Op.Params.Root["Input"]; input.Add().v = Doc.CoreDoc; PDFXEdit.ICabNode options = Op.Params.Root["Options"]; options["AND"].Add().v = "stream"; options["AND"].Add().v = "is"; options["AND"].Add().v = "defined"; SearchCallback clbk = new SearchCallback(pdfCtl.Inst); options["Callback"].v = clbk; options["Flags"].v = (int)PDFXEdit.PXV_SearchFlags.PXV_SearchFlag_GetTextQuads | (int)PDFXEdit.PXV_SearchFlags.PXV_SearchFlag_IncludePageText; Op.Do(); }