op.search
From PDF XChange PDF SDK
(Automatic page editing by robot) |
(→Sample) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
{{#customTitle:op.search}} | {{#customTitle:op.search}} | ||
{{#parentPage:PXV:Operations|op.search|operation}} | {{#parentPage:PXV:Operations|op.search|operation}} | ||
− | |||
{{ToReview}} | {{ToReview}} | ||
== Overview == | == Overview == | ||
− | The operation | + | The operation allows searching for words/phrases in the given folder or document(s). |
== Parameters == | == Parameters == | ||
Line 16: | Line 15: | ||
| class="op_param_name" | Input | | class="op_param_name" | Input | ||
| style="text-align:center" | Array | | style="text-align:center" | Array | ||
− | | Array of <code>IUnknown</code>-based objects. | + | | Array of <code>IUnknown</code>-based objects containing either a [[PXV:IAFS_Name|folder with documents]] that will be searched through or [[PXV:IPXV_Documet|documents]] that will be used for words/phrases search. |
|- | |- | ||
| class="op_param_name" | Output | | class="op_param_name" | Output | ||
| style="text-align:center;" | Array | | style="text-align:center;" | Array | ||
− | | | + | | Not used. |
|- | |- | ||
| class="op_param_name" | [[PXV:op_search_Options|Options]] | | class="op_param_name" | [[PXV:op_search_Options|Options]] | ||
Line 26: | Line 25: | ||
| Dictionary with options of the operation. | | Dictionary with options of the operation. | ||
|} | |} | ||
+ | |||
+ | == Sample == | ||
+ | <pre class="brush:c#">//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(); | ||
+ | } |
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(); }