[Tex/LaTex] Certain EPS files don’t convert with epstopdf

epstopdfmiktex

I seem to be having problems with certain EPS files, generated by Matlab. Using epstopdf, it generates an empty pdf file (which it then inserts into the document, leaving a void there).

It seems like my issue may be similar to this one, but it seems that that was never resolved. It also appears to be similar to this one as well, but again, it does not appear resolved.

I am using MiKTeX 2.9, on Windows 8.1, and the following MWE sort of works:

\documentclass{article}

\usepackage{graphicx}
\usepackage{epstopdf}

\begin{document}

% test.eps can be found at: http://1drv.ms/1EOjokZ
\includegraphics{test.eps}

% prob1_pdfa.eps can be found at: http://1drv.ms/11gMHjb
\includegraphics{prob1_pdfa.eps}

\end{document}

By that I mean that the first EPS displays properly, but the second does not. There are no errors in the console output (other than the 'Overfull \hbox' error I always seem to get).

This same MWE works on ShareLatex, which is what I used in the interim.

The EPS file which does not work was generated in Matlab r2014b using something like:

f=figure;
hist(rand(1,1e4),25)
print(f,'-depsc','sample.eps')

Best Answer

GUI

As Bernard pointed out, the epspdf-extra bundle is one possible choice. All you need to do is download epspdf-extra.zip and use the Windows installer provided to install epspdf with a buit-in Tcl/Tk runtime, which can be used as a GUI application (illustrated on page 3 of the user manual to the epspdf package).

command line

Alternatively you can download epspdf.0.6.0.zip from tex.aanhet.net/epspdf, and follow these instructions:

  • Extract all files into a folder <path to>\epspdf (e.g. C:\Program Files\epspdf).
  • In <path to>\epspdf create an empty text file with the name epspdf.bat. Then copy the following lines into the batchfile and adjust the script path to your settings:

    @echo off
    set ScriptPath=<path to>\epspdf
    texlua %ScriptPath%\epspdf.tlu %*
    

    where <path to> could be, for example, C:\Programs or "C:\Program Files" (the quotes " " are included).

  • Add <path>\epspdf to the system variable Path (Start Menu > right-click on Computer > Properties > Advanced System Settings > Environment Variables under the Advanced tab > look for the system variable Path and edit its value).

This approach allows you to use epspdf from the command line in combination with the \write18 feature (add --enable-write18, or the alias --shell-escape, to the list of arguments passed to the pdflatex compiler). With regard to the problematic EPS file, here's a MWE:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\immediate\write18{epspdf prob1_pdfa.eps}
\includegraphics[keepaspectratio=true,width=0.9\textwidth]{prob1_pdfa.pdf}
\end{document}

enter image description here


A somewhat more creative approach based on LaTeX code found on page 3 of this document is to define a command \includeeps with a mandatory argument that accepts the name of the EPS file (without the .eps extension) you wish to include in your document, and an optional argument that can pass options to the \includegraphics command:

\newcommand{\executeiffilenewer}[3]{%
\ifnum\pdfstrcmp%
{\pdffilemoddate{#1}}%
{\pdffilemoddate{#2}}%
>0%
{\immediate\write18{#3}}%
\fi%
}
\newcommand{\includeeps}[2][]{%
\IfFileExists{./#2.pdf}%
{\executeiffilenewer{#2.eps}{#2.pdf}{epspdf #2.eps}}%
{\immediate\write18{epspdf #2.eps}}%
\includegraphics[#1]{#2.pdf}
}

When a file is included via \inclueeps, the epspdf program is only called when no .pdf file exists, or the EPS file has been updated.

Examples of usage with file abc.eps as input:

\includeeps[width=6cm]{abc}
\includeeps{figures/abc}
\includeeps{../section/abc}
\includeeps[keepaspectratio=false,height=9cm]{../section/abc}
Related Question