Highlight multiple occurrence of a search term

Questions related to converting various types of documents
Post Reply
gauravrehan
Posts: 1
Joined: Thu Aug 28, 2008 1:13 am

Highlight multiple occurrence of a search term

Post by gauravrehan » Thu Aug 28, 2008 1:20 am

Is there a way of highlighting multiple search terms in the converted swf file?

Currently I can see that in javascript i can use searchtext() function to highlight the first occurrence of the search term. Is there a way of performing searchAll that can highlight all occurrences at once.
If this is not directly supported, is there any work around of achieving this behavior.

Waiting for the reply.

Thanks,
gaurav

staff
Posts: 281
Joined: Sat Dec 15, 2007 4:48 pm

Re: Highlight multiple occurrence of a search term

Post by staff » Thu Oct 16, 2008 4:57 am

In current version of Print2Flash there is no direct API for highlighting all occurrences of a search term in a converted document. However, such behavior may be implemented using Print2Flash Document API invoked from Flash AS2 movies. For example, you may use this code to highlight text from symbols 10 to 19 and from 30 to 39 on the first document page:

Code: Select all

var sh=p2f.getPage(1).getTextSnapshot()
sh.setSelected(10,20,true)
sh.setSelected(30,40,true)
To determine which symbols to highlight, you may retrieve page text using this additional code:

Code: Select all

var text=sh.getText(0,sh.getCount())
and search for all occurrences of the required search term in it.

pesenti
Posts: 7
Joined: Sat Jul 04, 2009 2:20 pm

Re: Highlight multiple occurrence of a search term

Post by pesenti » Sat Jul 04, 2009 2:30 pm

I can get this to work with the sample document provided in the SDK but I can't do it with any of the documents I generate. In the docapisample.fla I try to get the following

Code: Select all

_root.MyDoc.getPage(1).getTextSnapshot().getCount()
For your sample document this is 884 as expected. In all the documents that I generate (either through the API or through the print menu) it's 0. Note that I checked the following:

1. I set the PROTECTION_OPTION option properly (i.e., I allow programmatic access and don't disallow accessing the text - if I don't I get "undefined" not 0)
2. I wait that the document is fully loaded (this is calculated after clicking on the a button - on a side, trying to search the document right after it is loaded, even using your loading code example, does not work right away).
3. I can select text and search the document using your API.

Any help would be very appreciated.

pesenti
Posts: 7
Joined: Sat Jul 04, 2009 2:20 pm

Re: Highlight multiple occurrence of a search term

Post by pesenti » Sat Jul 04, 2009 6:56 pm

Is it possible that I hit this problem because I am testing the unregistered version? It works as well when I use documents converted through your website.

pesenti
Posts: 7
Joined: Sat Jul 04, 2009 2:20 pm

Re: Highlight multiple occurrence of a search term

Post by pesenti » Mon Jul 06, 2009 2:38 pm

I just bought a server version of your software and I am still getting the same issue. This is critical for us as we need to be able to find text in the page.

pesenti
Posts: 7
Joined: Sat Jul 04, 2009 2:20 pm

Re: Highlight multiple occurrence of a search term

Post by pesenti » Tue Jul 07, 2009 1:32 pm

I have found the issue (but still haven't found print2flash's support...). They now have a submovie called realmovie that contains the text. So you need to do

Code: Select all

p2f.getPage(1).realMovie.getTextSnapshot()

staff
Posts: 281
Joined: Sat Dec 15, 2007 4:48 pm

Re: Highlight multiple occurrence of a search term

Post by staff » Thu Jul 16, 2009 11:32 am

For the latest version you need to use a slightly modified code in order to make multiple text selections work properly:

Code: Select all

var sh=p2f.GetTextSnapshot(0) // first page
sh.setSelected(5,10,true)
sh.setSelected(15,20,true)
This code uses an undocumented GetTextSnapshot function to get a text snapshot. The argument to this function is a page number starting from zero.

Post Reply