I translated your example in the comments to something that compiles below.
You are using the wrong callback. If you look in the pdf you will see something like this:
/Span <</ActualText (test)>> BDC EMC 3 0 obj
<< /Length 205 >>
This means that your BDC-operator ended outside the page stream. The pdf is broken.
The documentation describes the callback like this:
This callback is called whenever LuaTEX is ready to move stuff to the main vertical list. You can
use this callback to do specialized manipulation of the page building stage like imposition or
if a=="new_graf" then
pdf.print ("direct","/Span <</ActualText (test)>> BDC ")
pdf.print ("direct","EMC ")