When I try to compile, for example, this code in my document:

\pdfextension literal direct{/Span <</ActualText (First paragraph on page one)>> BDC}
tex.print("my text")
\pdfextension literal direct{EMC}

I have a problem with the compilation of the document.

How I can use the command \pdfextension in Lua code?

  • 3
    please always make it easy for people to help you by providing a test file that reproduces the error. – David Carlisle Mar 20 at 20:09
  • 3
    You can't/shouldn't use luatex tex-commands like \pdfextension inside a luacode environment, it is only for luacode. – Ulrike Fischer Mar 20 at 20:17
  • But what command i can use in luacode enviroment,to add span in the page. – Aleksandr Kozlovskiy Mar 20 at 21:04
  • 1
    You should make a complete example so that it is clear where in the page stream you want to inject the BDC operator. – Ulrike Fischer Mar 20 at 22:13
  • 1
    Don't put code in the comments. Edit your question. And if you want me to see your comment you should ping me with @UlrikeFischer. – Ulrike Fischer Mar 20 at 23:27

I translated your example in the comments to something that compiles below.

But ...

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 column balancing.

function f(a)
 texio.write_nl("Value "..a)
 if a=="new_graf" then
  if b%2==0
   pdf.print ("direct","/Span <</ActualText (test)>> BDC ")
   pdf.print ("direct","EMC ")

 paragraph one

 paragraph two

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.