[luatex] warning (pdfe lib): no valid pdf file

Reinhard Kotucha reinhard.kotucha at gmx.de
Wed Jun 21 01:18:49 CEST 2023


Hi,
when I execute the file

-----------------------------------
#!/usr/bin/env texlua

local doc = pdfe.open ('rules.pdf')
-----------------------------------

luatex aborts with the messages:

   warning  (pdfe lib): no valid pdf file 'rules.pdf'

   warning  (pdfe lib): lua <pdfe document> expected


This happens with many PDF files though they can be processd
perfectly by other programs (PDF viewers).  I don't have a complete
overview yet but at a first glance it seems that only PDF files
*not* created by TeX are affected.

As an example I attach the file rules.pdf, created by Ghostscript.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rules.pdf
Type: application/pdf
Size: 10303 bytes
Desc: not available
URL: <https://tug.org/pipermail/luatex/attachments/20230621/8bbd133b/attachment-0001.pdf>
-------------- next part --------------


I doubt that this file is an invalid PDF file but what puzzles me is
that the first message obviously comes from the function
pdfelib_open() in lpdfelib.c

   static int pdfelib_open(lua_State * L)
   {
       const char *filename = luaL_checkstring(L, 1);
       ppdoc *d = ppdoc_load(filename);
       if (d == NULL) {
           formatted_warning("pdfe lib","no valid pdf file '%s'",filename);
       } else {
           pdfe_document *p = (pdfe_document *) lua_newuserdata(L, sizeof(pdfe_document));
           luaL_getmetatable(L, PDFE_METATABLE);
           lua_setmetatable(L, -2);
           p->document = d;
           p->open = true;
           p->isfile = true;
           p->memstream = NULL;
           return 1;
       }
       return 0;
   }

and the message is invoked when ppdoc_load(filename) returns NULL.  But
ppdoc_load(filename) in ppload.c returns NULL if fopen() fails:

   ppdoc * ppdoc_load (const char *filename)
   {
     FILE *file;
     iof_file input;
     if ((file = fopen(filename, "rb")) == NULL)
       return NULL;
     iof_file_init(&input, file);
     input.flags |= IOF_CLOSE_FILE;
     return ppdoc_create(&input);
   }


This is confusing.  If fopen() fails, how can pdfe know that the PDF
file is invalid?

I now assume that the message is not triggered by fopen(), otherwise I
wouldn't encounter different behavior with different PDF files.  And
problems with file permissions can be excluded.

But what causes pdfe to assume that rules.pdf is an invalid PDF file?

I wouldn't mind if it's only one file which cannot be processed by the
pdfe library but there are many and they all can be processed
perfectly by various PDF viewers.

Can anybody enlighten me?

Regards,
  Reinhard

--
------------------------------------------------------------------
Reinhard Kotucha                            Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover                    mailto:reinhard.kotucha at gmx.de
------------------------------------------------------------------


More information about the luatex mailing list.