[Dev-luatex] pdfe error / question
tex at 2krueger.de
Fri Mar 22 19:48:46 CET 2019
---- On Fri, 22 Mar 2019 18:39:17 +0100 Ulrike Fischer <news3 at nililand.de> wrote ----
> According to the documentation pdfe.status can be use to check if a
> pdf has been opened. But when I try
> I get an error
> (./test-utf8.tex[\directlua]:1: attempt to call a nil value (field
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]]
-- An easier way to get the same dictionary:
Resulting in the output (for some example main.pdf file):
94 8 <pdfe.dictionary 0x2d86f11> 1
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.)
> Ulrike Fischer
> dev-luatex mailing list
> dev-luatex at ntg.nl
More information about the dev-luatex