No Selection showed

Hello

i used the wpf example from the viewer control to build an custom textsearch. (with search result count). when i reselected the result with:

_viewer.Select(_selections[_selectionIndex]); _viewer.SetVScrollPos(_viewer.GetVScrollPos()); _viewer.SetHScrollPos(_viewer.GetHScrollPos()); var b = _viewer.HasSelection();

_selections[_selectionIndex] is an object from type HIGHLIGHTS.

when i use select(highlights highlight) then _viewer.HasSelection() is true but i didn’t see
the highlighted text in the document. When i start the samplecode then it start normaly!

Daniel

Hello

has anyone the same problem? I don’t know why the sample works correct and when i used the same code in my project it didn’t works!

Daniel
Am Freitag, 8. November 2013 11:33:52 UTC+1 schrieb Daniel Lutz:

Hello

i used the wpf example from the viewer control to build an custom textsearch. (with search result count). when i reselected the result with:

_viewer.Select(_selections[_selectionIndex]); _viewer.SetVScrollPos(_viewer.GetVScrollPos()); _viewer.SetHScrollPos(_viewer.GetHScrollPos()); var b = _viewer.HasSelection();

_selections[_selectionIndex] is an object from type HIGHLIGHTS.

when i use select(highlights highlight) then _viewer.HasSelection() is true but i didn’t see
the highlighted text in the document. When i start the samplecode then it start normaly!

Daniel

Hi Daniel,

The reason that this works for the sample is because of the PDFViewCtrlWPFTools sample that is referenced from the PDFViewWPFDemo. The tools will react when the scroll position changes and add text selection to the pages on screen. So when you scroll the page into view, it will draw the selection for you.

The PDFViewWPF does not draw selection for your automatically, it has to be done by the user. Therefore, I suggest that you look at the PDFViewCtrl.xaml.cs in the PDFViewWPF demo. See Current_View_FindTextFinished(PDFViewWPF viewer, bool found, PDFViewWPF.Selection selection) and especially the HighlightSelection function that it uses. This draws the selection, and then actually clears the selection but keeps the text highlighted, so that Tool.cs doesn’t double the work. You would have to notify Tool.cs every time the selection changed if you wanted it to do the highlighting for it, else it will not highlight the second found entry on the same page, because it won’t redraw the canvas.

I hope this helps you understand how TextSelection, FindText, TextSearch, and highlighting found text works. Please let us know if you have any further questions.

Best Regards,
Tomas Hofmann

Hello now i tested the highlight function. It works correct. But i have a problem to select
the results. I use the same code like you in your example code. For small pdfs it works correctly, but when i search
in example the pdf spezification with 1300 pages the word “pdf” he search on every page correctly. know i select any result in the listboy and run
the code

_viewer.Select(HIGHLIGHTObj);

Now I get a PDFException. The same code in your example works correctly!
Am Freitag, 8. November 2013 11:33:52 UTC+1 schrieb Daniel Lutz:

Hello

i used the wpf example from the viewer control to build an custom textsearch. (with search result count). when i reselected the result with:

_viewer.Select(_selections[_selectionIndex]); _viewer.SetVScrollPos(_viewer.GetVScrollPos()); _viewer.SetHScrollPos(_viewer.GetHScrollPos()); var b = _viewer.HasSelection();

_selections[_selectionIndex] is an object from type HIGHLIGHTS.

when i use select(highlights highlight) then _viewer.HasSelection() is true but i didn’t see
the highlighted text in the document. When i start the samplecode then it start normaly!

Daniel

Okay now i now the problem:

`

returnArgs = e;
this.Dispatcher.BeginInvoke((System.Action)delegate()
{
this.ListSearchResults.Items.Clear();
});
SearchResults.Clear();
hlt_list.Clear();

if (_viewer.GetDoc() != null)
textSearch = new pdftron.PDF.TextSearch();
else
throw new Exception(“WholeDocumentSearchControl Document property cannot be null.”);

pdftron.PDF.TextSearch.SearchMode mode = (e.Argument as InformationForSearch).Mode;
textSearch.Begin(_document, SearchTerm, (Int32)mode, 1, _viewer.GetPageCount());
FoundCount = 0;
CurrentPage = 0;

int page_num = 0;
String result_str = string.Empty;
String ambient_str = string.Empty;
Highlights hlts = new Highlights();

try
{
while (true)
{
System.Threading.Thread.Sleep(1);
_document.Lock();

if (bw.CancellationPending)
{
_document.Unlock();
returnArgs.Cancel = true;
return;
}

hlts = new Highlights();
resultCode = textSearch.Run(ref page_num, ref result_str, ref ambient_str, hlts);
CurrentPage = textSearch.GetCurrentPage();
bw.ReportProgress(CurrentPage);

if (resultCode == pdftron.PDF.TextSearch.ResultCode.e_found)
{
SearchResult result = new SearchResult(page_num, result_str, ambient_str, hlts);
SearchResults.Add(result);
hlt_list.Add(hlts);
FoundCount++;

this.Dispatcher.BeginInvoke((System.Action)delegate()
{
TextBlock b = new TextBlock();
TextBlock t = new TextBlock();
b.Text = result.AmbientString;
t.Text = result.ToolTipString;
FormatText(ref b, result.ResultString, FontWeights.Bold);
FormatText(ref t, result.ResultString, FontWeights.Bold);

ToolTipService.SetToolTip(b, t);
ListSearchResults.Items.Add(b);
});

_document.Unlock();
}
else if (resultCode == pdftron.PDF.TextSearch.ResultCode.e_page)
{
_document.Unlock();
}
else
{
_document.Unlock();
return;
}
}
}
catch (pdftron.Common.PDFNetException ex)
{
_document.Unlock();

System.Diagnostics.Debug.WriteLine(ex.ToString());
}

`

okay when the code runs in the backworker thread like the example from your software the i get after 1200 page the PDFNetexception (ex). The exception means that it was try to load a wrong file! I don’t know why because i am not change the document or other things.
What can be the problem!
Am Freitag, 8. November 2013 11:33:52 UTC+1 schrieb Daniel Lutz:

Hello

i used the wpf example from the viewer control to build an custom textsearch. (with search result count). when i reselected the result with:

_viewer.Select(_selections[_selectionIndex]); _viewer.SetVScrollPos(_viewer.GetVScrollPos()); _viewer.SetHScrollPos(_viewer.GetHScrollPos()); var b = _viewer.HasSelection();

_selections[_selectionIndex] is an object from type HIGHLIGHTS.

when i use select(highlights highlight) then _viewer.HasSelection() is true but i didn’t see
the highlighted text in the document. When i start the samplecode then it start normaly!

Daniel

PS: The exception is the following: base {System.Exception} = {“boost::thread_resource_error: Es wurde versucht, eine Datei mit einem falschen Format zu laden”}
Am Freitag, 8. November 2013 11:33:52 UTC+1 schrieb Daniel Lutz:

Hello

i used the wpf example from the viewer control to build an custom textsearch. (with search result count). when i reselected the result with:

_viewer.Select(_selections[_selectionIndex]); _viewer.SetVScrollPos(_viewer.GetVScrollPos()); _viewer.SetHScrollPos(_viewer.GetHScrollPos()); var b = _viewer.HasSelection();

_selections[_selectionIndex] is an object from type HIGHLIGHTS.

when i use select(highlights highlight) then _viewer.HasSelection() is true but i didn’t see
the highlighted text in the document. When i start the samplecode then it start normaly!

Daniel

Hello

now i have no exception in using the pdftron library. The exception throws only in the unregistered trial version of the library. Now i am using a registered version and no exception is throwing.
I hope the fact can helps to find the problem of the exception.

Best regards
Daniel
Am Freitag, 8. November 2013 11:33:52 UTC+1 schrieb Daniel Lutz:

Hello

i used the wpf example from the viewer control to build an custom textsearch. (with search result count). when i reselected the result with:

_viewer.Select(_selections[_selectionIndex]); _viewer.SetVScrollPos(_viewer.GetVScrollPos()); _viewer.SetHScrollPos(_viewer.GetHScrollPos()); var b = _viewer.HasSelection();

_selections[_selectionIndex] is an object from type HIGHLIGHTS.

when i use select(highlights highlight) then _viewer.HasSelection() is true but i didn’t see
the highlighted text in the document. When i start the samplecode then it start normaly!

Daniel