Tx · LaTeX & TikZ

How to Fix “Unable to Load Picture or PDF File” in XeLaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Check file support

    XeLaTeX normally accepts PDF, PNG, and JPEG images; convert EPS files to PDF first.

  2. 2. Verify the path

    Put the image beside the .tex file and use its exact filename, including capitalization and extension.

  3. 3. Test a minimal file

    Compile a short document with graphicx and one image to isolate the problem.

  4. 4. Check the compiler

    Set TeXstudio to use XeLaTeX, then inspect the log for the exact file and error.

Advertisement

The message “Unable to load picture or PDF file” means XeLaTeX’s graphics driver could not find or read the file named by \includegraphics. Windows 8 by itself does not normally prevent image inclusion. The most useful first step is to reduce the document to a small test and check the exact filename and format.

XeLaTeX normally includes PDF, PNG, and JPEG images. The graphicx package selects a suitable driver automatically, so you generally should not specify a pdftex driver option when compiling with XeLaTeX.

Try a minimal example

Put a supported image named example.png in the same folder as this source file, then compile it with XeLaTeX:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\includegraphics[width=0.6\textwidth]{example.png}
\end{document}

This complete document needs only the standard graphicx package. If it compiles, the problem is likely in the original document’s path, filename, file format, or graphics options—not in XeLaTeX generally.

Check the filename and location

For the first test, keep the image in the same directory as the .tex file and refer to it by its filename alone. Check that:

  • The spelling, capitalization, and extension match the actual file. A file called figure.PNG is not necessarily the same name as figure.png in every setup.
  • The file is really an image or PDF, not a different file that was renamed with an image extension.
  • You are compiling the source file you think you are compiling. TeXstudio may use a different root document when a project contains several .tex files.

If the image is in another folder, use a relative path with forward slashes, for example \includegraphics{images/plot.pdf}. On Windows, avoid writing a normal path with backslashes directly in a TeX command: backslashes begin TeX commands. You can also use \graphicspath{{images/}} after loading graphicx and then refer to plot.pdf by name.

Paths containing spaces can work, but they make troubleshooting harder. Temporarily move the image to a short, space-free path and use a simple filename such as test.png. If that fixes the error, restore the original location carefully or rename the file.

Check the image format

Use PDF, PNG, or JPEG for a straightforward XeLaTeX test. An EPS file is not a PDF, even if a viewer can open it; convert it to PDF before including it in a typical XeLaTeX workflow. If you have a PDF image that fails, open it in a PDF viewer and try saving or exporting it as a new PDF. A damaged, encrypted, or unusually constructed PDF may not be readable by the PDF-handling tools used in your TeX installation.

When including a PDF, you can specify a page if needed, for example:

\includegraphics[page=2,width=0.8\textwidth]{report.pdf}

The default is the first page. If the error names a PDF page or reports a PDF parsing problem, test the same file by itself and check whether the PDF opens normally.

Confirm TeXstudio is using XeLaTeX

In TeXstudio, check the selected compiler or build command and make sure it runs XeLaTeX, not plain LaTeX or an incorrectly configured command. Also remove options such as \usepackage[pdftex]{graphicx} from a XeLaTeX document; forcing the pdfTeX driver can cause driver conflicts. Normally, use only \usepackage{graphicx}.

To separate an editor setting from a file problem, compile the minimal test from a command prompt in the directory containing the source and image:

xelatex test.tex

If command-line compilation works but TeXstudio does not, the issue is likely in TeXstudio’s compiler configuration, working directory, or selected root file. If both fail, read the .log file for the precise filename and the first graphics-related error. A missing-file message points to the path or name; a PDF parsing message points more strongly to the file or to an outdated TeX installation.

Common mistakes

  • Using the wrong extension: figure.pdf and figure.png are different files. Include the extension explicitly while diagnosing.
  • Using Windows backslashes: Write images/figure.png, not a path with unescaped backslashes.
  • Forcing the wrong driver: Do not tell graphicx to use pdftex when compiling with XeLaTeX.
  • Assuming every graphic format is supported directly: Convert EPS to PDF for the simplest XeLaTeX workflow.
  • Ignoring the log: The wording and filename in the first relevant error often distinguish a path problem from a file-reading problem.

If the minimal test still fails with a supported image beside the source file, update or repair the TeX distribution and try again. Older TeX installations may contain outdated PDF-handling components. When asking for help, include the minimal source, the exact filename and extension, the compiler command, and the first relevant lines from the log.

References

  1. The LaTeX Graphics Companion, 2nd edition — Michel Goossens, Frank Mittelbach, Sebastian Rahtz, and others
  2. The graphics package on CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.