---- On Fri, 22 Mar 2019 18:39:17 +0100 Ulrike Fischer <ne...@nililand.de> 
wrote ----
 > According to the documentation pdfe.status can be use to check if a
 > pdf has been opened. But when I try 
 > 
 > \directlua{
 >  dict=pdfe.open("testinput.pdf")
 >  pdfe.status(dict)}
 > \bye
 > 
 > I get an error 
 > (./test-utf8.tex[\directlua]:1: attempt to call a nil value (field
 > 'status')
 > 

The function actually exists but it is called `getstatus` instead of `status`.

 > 
 > And how I'm supposed to extract an object reference from a
 > dictionary? There are commands getinteger, getstring but nothing
 > that looks like a "getreference".
 > 

Normally you do need to do this, just use `getdictionary` etc. and references 
get resolved automatically.
If you really need the reference, use getfromdictionary. In contrast to the 
documentation, this function also
accepts a key instead of an index. (If called with a key, the key is not 
returned.)
If the key points to a reference, the function returns the type 10, the 
reference object and the reference number
(This is also different than the documentation, which suggests that it only 
returns the number.)
Also getfromreference does not only return the referenced object, but also it's 
type.

So you get

local file = pdfe.open'main.pdf'
print('Status: ' .. pdfe.getstatus(file))
local catalog = pdfe.getcatalog(file)
local t, ref, refnum = pdfe.getfromdictionary(catalog, 'Names')
if t ~= 10 then
  error[[No reference found]]
end
print(refnum, pdfe.getfromreference(ref))
-- An easier way to get the same dictionary:
print(catalog.Names)
pdfe.close(file)

Resulting in the output (for some example main.pdf file):

Status: 0
94    8    <pdfe.dictionary 0x2d86f11>    1
<pdfe.dictionary 0x2d86f11>

meaning the file is not encrypted(0), the reference it to object number 94 
which is a dictionary(8) containing 1 entry.

Do not try to print the reference object, the tostring helper is broken so it 
leads to a fatal Lua error. (It uses `%i`, but it would have to use `%d` to 
work.)


Best regards
Marcel Krüger

 > 
 > -- 
 > Ulrike Fischer 
 > http://www.troubleshooting-tex.de/
 > 
 > _______________________________________________
 > dev-luatex mailing list
 > dev-luatex@ntg.nl
 > https://mailman.ntg.nl/mailman/listinfo/dev-luatex
 >


_______________________________________________
dev-luatex mailing list
dev-luatex@ntg.nl
https://mailman.ntg.nl/mailman/listinfo/dev-luatex

Reply via email to