How to fix: Jupyter PDF export PNG (in markdown) inclusion failed

Viewed 1250

Updates at end

After an extremely painful update process largely because PDF export uses XeLaTeX and I have always preferred LaTeX, so different packages needed)...

(Important aside: I think pandoc expects to find everyshi.sty in package MS, but as reported on CTAN it's no longer in that package)

PDF creation fails with this info from the server:

notebook.tex:1678: Unable to load picture or PDF file '
dvipdfmx:fatal: Image inclusion failed for "attachment:9e002d53-d7a5-42e1-8b51-0fdec8f4dad5.png".
No output PDF file written.

Sorry, but xelatex did not succeed.
    The log file hopefully contains the information to get MiKTeX going again:
      C:\Users\usernamehere\AppData\Local\MiKTeX\2.9\miktex\log\xelatex.log

The xelatax.log shows:

2021-06-10 08:02:26,620+0100 INFO  xelatex.core - start process: miktex-dvipdfmx.exe --miktex-enable-installer -q -E -o notebook.pdf
2021-06-10 08:02:28,594+0100 FATAL xelatex.core - Invalid argument
2021-06-10 08:02:28,594+0100 FATAL xelatex.core - Function: fwrite
2021-06-10 08:02:28,594+0100 FATAL xelatex.core - Result: 22
2021-06-10 08:02:28,594+0100 FATAL xelatex.core - Data: <no data>
2021-06-10 08:02:28,594+0100 FATAL xelatex.core - Source: Libraries\MiKTeX\TeXAndFriends\include\miktex/C4P/C4P.h:646
2021-06-10 08:02:28,594+0100 FATAL xelatex - Invalid argument
2021-06-10 08:02:28,594+0100 FATAL xelatex - Info: 
2021-06-10 08:02:28,594+0100 FATAL xelatex - Source: Libraries\MiKTeX\TeXAndFriends\include\miktex/C4P/C4P.h
2021-06-10 08:02:28,594+0100 FATAL xelatex - Line: 646
2021-06-10 08:02:28,596+0100 INFO  xelatex - this process (37528) finishes with exit code 1

And if we then look in miktex-dvipdfmx.log we find the other end of the call...

2021-06-10 08:02:26,808+0100 INFO  miktex-dvipdfmx - this process (4364) started by 'xelatex' with command line: miktex-dvipdfmx.exe --miktex-enable-installer -q -E -o notebook.pdf
2021-06-10 08:02:28,558+0100 ERROR miktex-dvipdfmx - Image inclusion failed for "attachment:9e002d53-d7a5-42e1-8b51-0fdec8f4dad5.png".
2021-06-10 08:02:28,559+0100 INFO  miktex-dvipdfmx - this process (4364) finishes with exit code 1

So. Image inclusion failed for the png, which is is an attachment in a markdown cell (a screen grab of previous output so that long-running code doesn't always have to be re-run).

Can anyone confirm this should work (I have seen something, somewhere that there was an issue with images in markdown cells a long time ago) and if so, explain how to resolve this issue?

Update I 29/06/2021

From the xelatex log: there's an "invalid argument message" and the arguments "-q -E -o" just above are for miktex-dvipdfmx.exe, but referring to the dvipdfmx manual I can't find the -q, -o arguments...

Then checking the BASIC manual for dvipddf () and options there -o is the output filename (not a great surprise) but still no sign of a -q option.

That is at least consistent, but... what? How? etc. etc. etc.

Update II of 29/06/2021

Updated miktex; found a new item, miktex-dvipdfmx-bin-x64-2, has been installed! Re-ran notebook export. Different error:

nbconvert failed: PDF creating failed, captured latex output:
Failed to run "xelatex notebook.tex -quiet" command:

notebook.tex:561: Undefined control sequence

checking the miktex-dvipdfmx.log I find

2021-06-10 08:02:26,808+0100 INFO  miktex-dvipdfmx - this process (4364) started by 'xelatex' with command line: miktex-dvipdfmx.exe --miktex-enable-installer -q -E -o notebook.pdf
2021-06-10 08:02:28,558+0100 ERROR miktex-dvipdfmx - Image inclusion failed for "attachment:9e002d53-d7a5-42e1-8b51-0fdec8f4dad5.png".
2021-06-10 08:02:28,559+0100 INFO  miktex-dvipdfmx - this process (4364) finishes with exit code 1

So the argument error was (presumably) resolved by the use of miktex-dvipdfmx-bin-x64-2, and now there's some other issue in the tex itself

Unfortunately, a full search of C:\ and the separate documents drive fails to find notebook.tex so investigation dead-ends here.

However, note that PDF export works OK for a notebook without embedded "attachments" - I wonder whether it simply can't find the attachment "files"

Final error report from jupyter as 500 server error:

nbconvert failed: PDF creating failed, captured latex output:
Failed to run "xelatex notebook.tex -quiet" command:

notebook.tex:496: Undefined control sequence [17 times]
...
notebook.tex:2119: Unable to load picture or PDF file '
dvipdfmx:fatal: Image inclusion failed for "attachment:9e002d53-d7a5-42e1-8b51-0fdec8f4dad5.png".

No output PDF file written.

Sorry, but xelatex did not succeed.

The log file hopefully contains the information to get MiKTeX going again:

  C:\Users\Julian\AppData\Local\MiKTeX\2.9\miktex\log\xelatex.log

And the xelatex log says there was no data

2021-06-29 08:30:42,590+0100 INFO  xelatex.core - start process: miktex-dvipdfmx.exe --miktex-enable-installer -q -E -o notebook.pdf
2021-06-29 08:30:43,984+0100 FATAL xelatex.core - Invalid argument
2021-06-29 08:30:43,984+0100 FATAL xelatex.core - Function: fwrite
2021-06-29 08:30:43,984+0100 FATAL xelatex.core - Result: 22
2021-06-29 08:30:43,984+0100 FATAL xelatex.core - Data: <no data>
2021-06-29 08:30:43,984+0100 FATAL xelatex.core - Source: Libraries\MiKTeX\TeXAndFriends\include\miktex/C4P/C4P.h:646
2021-06-29 08:30:43,984+0100 FATAL xelatex - Invalid argument
2021-06-29 08:30:43,984+0100 FATAL xelatex - Info: 
2021-06-29 08:30:43,984+0100 FATAL xelatex - Source: Libraries\MiKTeX\TeXAndFriends\include\miktex/C4P/C4P.h
2021-06-29 08:30:43,984+0100 FATAL xelatex - Line: 646
2021-06-29 08:30:43,986+0100 INFO  xelatex - this process (38968) finishes with exit code 1

Possibly related: github nbconvert issues

2 Answers

I am having the freaking same problem here too. Now my temporary solution is just to use the Chrome browser feature of print (save as pdf), but then the header part and the footnote just looks so tasteless and annoying.

I was running into this issue as well.

My solution ... use the full path in your attachment definition to the image instead of the relative path. Although, it doesn't render in VS Code when I do that, it does allow nbconvert to now successfully find the file and create the PDF.

Problematic code: (test image)[test_image.jpg]

Working code: (test image)[C:\test_image.jpg]

I cannot say for sure, but I noticed in my error log that it was writing temp files into AppData. I suspected that it was not pulling the images in at that time, then failing to find them relative to that temp file.

Related