op.search

From PDF XChange PDF SDK
Revision as of 09:43, 23 January 2017 by Palamar (Talk | contribs) (Sample)

Jump to: navigation, search


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
{
	public void OnFinish(int nResCode)
	{
				
	}

	public void OnNewEntry(PDFXEdit.IPXV_SearchEntry pEntry)
	{
		//Highlighting first item in the first document
		uint i = 0;
		PDFXEdit.IPXC_Document doc = null;
		PDFXEdit.IPXC_Page page = 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];
				}
				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);
							//Now we'll need to check whether the document is opened so that we can highlight it
							PDFXEdit.IPXV_Document vDoc = m_Inst.FindDocByCoreDoc(doc);
							if (vDoc != null)
							{
								PDFXEdit.IPXV_DocHighlighter highlighter = vDoc.AddNewHighlighter(PDFXEdit.PXV_DocHighlightType.PXV_DocHighlight_Page);
								PDFXEdit.PXV_DocHighlightAdvanced ha = new PDFXEdit.PXV_DocHighlightAdvanced();
								highlighter.Add(page, quads, null, null, ref ha, 0);
							}
						}
					}

				}
			}
			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();
	options["Callback"].v = clbk;
	Op.Do();
}