[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Swftools-common] PDF2SWF and getTextSnapShot()
From: |
Mark A. Lowe |
Subject: |
RE: [Swftools-common] PDF2SWF and getTextSnapShot() |
Date: |
Thu, 15 Nov 2007 11:28:32 +1100 |
Many thanks Fabio,
I've managed to get somewhere with your actionscript.
I also had a problem with how I was creating my swf from pdf2swf.
For everyone else make sure you follow these steps:
1. Use Flash 8 or previous version (I used 6) with the -T command : pdf2swf -T 6
2. Use the -f command for full fonts : pdf2swf -f
3. Test your outputted swf with: swfdump -t filename.swf , you should see a
list of DEFINETEXT statements and the corresponding text. Due to a font
conflict I was seeing DEFINETEXT followed by jumbled up text on my first pdf.
4. Test your outputted swf with: swfstrings filename.swf, you should see your
text and a LOT of ???????s. Again, I had garbage text when trying to convert my
original PDF.
If the swfdump and swfstrings tests are working, load your pdf2swf.swf into
Flash. Publish it for 8.
I loaded it into a movieclip on my root timeline called 'loader' :
loader.loadMovie("pdf2swf_files/6new.swf");
I have a movieclip called 'searchText_mc' and have the following code for it:
searchText_mc.onRelease = function() {
hltext ("wonderful");
}
And then the hltext is as Fabio provided. This will yellow-highlight all the
occurrences of the search string:
function hltext ( txt )
{
trace("hltext");
var mc = _root.loader;
var my_snap:TextSnapshot = mc.getTextSnapshot();
var start_pos:Number = 0;
start_pos = my_snap.findText ( start_pos, txt, false );
trace("start_pos : " + start_pos);
while ( start_pos > 0 )
{
trace ( start_pos );
my_snap.setSelected( start_pos, start_pos + txt.length,
true );
start_pos += txt.length;
start_pos = my_snap.findText ( start_pos, txt, false );
}
}
If anyone would like some sample files give me a shout,
mark lowe
senior multimedia developer
multimedia resource australia
t:
+61 3 9602 4750
f:
+61 3 9606 0408
e:
address@hidden
w:
www.mmr.com.au
level 2, 351 elizabeth st, melbourne vic 3000 [ courier correspondence ]
p.o. box 205, fitzroy vic 3065 [ all other correspondence ]
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Fabio Rotondo
Sent: Wednesday, November 14, 2007 8:39 PM
To: address@hidden
Subject: Re: [Swftools-common] PDF2SWF and getTextSnapShot()
Mark A. Lowe wrote:
Hi Mark,
> > I’m still learning it and the answer may be obvious, but where would I
> > find some documentation/examples on how to search the text once I have
> > loaded my (pdf2swf) .swf file into my Flash application?
this is a common question. You should have had a look to the mailing
list archives before asking ;-)
that said, here there is my ActionScript code to highlight the text
inside a PDF page. It works with Flash 8 or previous ONLY because the
new Flash 9 has a different AVM interpreter (AVM2) and many things have
changed.
Please note:
- ``txt`` is the text to search and highlight inside your page
- ``mc`` points to _root.text that's where I was keeping my swf/pdf page
you should change that so it references yours.
Here is the code:
function hltext ( txt )
{
var mc = _root.text;
var my_snap:TextSnapshot = mc.getTextSnapshot();
var start_pos:Number = 0;
start_pos = my_snap.findText ( start_pos, txt, false );
while ( start_pos > 0 )
{
trace ( start_pos );
my_snap.setSelected( start_pos, start_pos + txt.length,
true );
start_pos += txt.length;
start_pos = my_snap.findText ( start_pos, txt, false );
}
}
Have fun!
Ciao,
Fabio