# Failed to load pdf with includegraphics in LuaLaTeX

I have this code:

% !TeX encoding = UTF-8
\documentclass[12pt,letterpaper,oneside]{book}
\usepackage{graphicx}
\begin{document}
\includegraphics{imagenes/contacto.pdf}
\end{document}


but I get the next error:

!LuaTeX error (file imagenes/contacto.pdf): PDF inclusion: could not stat() fil e 'E:/Work/imagenes/contacto.pdf' ==> Fatal error occurred, no output PDF file produced!

This happens only with pdf's and LuaLaTeX, pdfLaTex compile it well and replacing with jpg's images works as well in LuaTeX. What can I do to make it work in LuaLaTeX?

• Welcome! Please try substituting \includegraphics{example-image-a.pdf} for your current \incluegraphics line. If that doesn't work, please post the log file. My current guess is that it just can't find the file and its being a PDF is irrelevant, but testing with a standard PDF image will show for sure.
– cfr
Mar 21, 2018 at 1:03
• No, it doesn't work, even if I put the image in the same folder, besides it is capable to find jpg's. Mar 21, 2018 at 1:10

The error message is caused by function get_file_checksum in texk/web2c/luatexdir/image/pdftoepdf.w (from LuaTeX 0.95):

static char *get_file_checksum(const char *a, file_error_mode fe)
{
struct stat finfo;
char *ck = NULL;
if (stat(a, &finfo) == 0) {
off_t size = finfo.st_size;
time_t mtime = finfo.st_mtime;
ck = (char *) malloc(PDF_CHECKSUM_SIZE);
if (ck == NULL)
formatted_error("pdf inclusion","out of memory while processing '%s'", a);
snprintf(ck, PDF_CHECKSUM_SIZE, "%" PRIu64 "_%" PRIu64, (uint64_t) size, (uint64_t) mtime);
} else {
switch (fe) {
case FE_FAIL:
formatted_error("pdf inclusion","could not stat() file '%s'", a);
break;
case FE_RETURN_NULL:
if (ck != NULL)
free(ck);
ck = NULL;
break;
default:
assert(0);
}
}
return ck;
}


The exact return value of function stat would tell a reason, why the call failed, see the manual page for stat. Unhappily, the exact value is not evaluated and added to the error message.

It is very odd, that stat fails here. Go through the list of error cases in the cited manual page. The following test should succeed. Open a command window (cmd.exe):

dir E:\Work\imagenes\contacto.pdf


You should see the file date and file size. This test should exclude most of the error causes (path component is not a directory, problems of directory access, path/component name too long, ...).

A wild guess. Maybe there is some interaction with the anti-virus program that hook into system calls to do its job, but causing trouble, if this "hooking" is not perfectly done in a transparent manner in case of the LuaTeX binary. This can cause

• Thanks you very much. Aparently it was a combination of both: a large path and the antivirus. The stranger thing to me is that I don't know why but it doesn't happened with jpg's images (with the same original path and name). I know it's a different question but do you know why this behavior? Mar 21, 2018 at 4:52
• @ErnestoIglesias Images in other formats (JEPG , ...) just use a different code path, i.e., method get_file_checksum is not called for them. Mar 21, 2018 at 5:53
• Could you be more explicit in terms of when path/component name are too long, I started trying some diferents path, including longer path than the original: some of them fail other don't. Note: the original have only 45 characters, I don't think it's rasonably long. Mar 21, 2018 at 17:32
• @ErnestoIglesias See MAXPATH. The length including drive and terminating <nul> byte must be less or equal 260. Mar 21, 2018 at 18:49
• Well, I never reached more than 100! that's an odd behavior of lualatex then. Is it a bug? Mar 21, 2018 at 20:09

I am not going to uncheck @HeikoOberdiek answer because mine is just a try and error solution and his solution have the real insight in the problem. But I think it is incomplete without noticing that special characters (á,é,í,ó,ú) in the path also make stat() fail.

My solution: change all folders names that include those characters.

Interensting fact: the character ñ don't have the same problem, I can't tell why.