I try to run:

C:\Users\Oleg\Desktop>epstopdf.exe test5-reference.eps

and I get just an a blank .pdf with the following:

Error: /undefined in uageLevel:
Operand stack:

Execution stack:
%interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   
%stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
%stopped_push   1926   1   3   
%oparray_pop   1925   1   3   
%oparray_pop   --nostringval--   1909   1   3   
%oparray_pop   1803   1   3   
%oparray_pop   --nostringval--   
%errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2
%stopped_push   --nostringval--
Dictionary stack:
   --dict:1169/1684(ro)(G)--   --dict:0/20(G)--   --dict:81/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
MiKTeX GPL Ghostscript 9.05: Unrecoverable error, exit code 1
epstopdf.exe: Invalid argument

No idea what might be wrong. I am on Win7 64bit.

Link to test5-reference.eps


Matlab R214b is used to create the .eps with the call:

print(gcf, '-depsc', filename)

which uses settings specified in printjob(). Specifically:

pj.PostScriptTightBBox = 1; %True if want to have a tight BoundingBox

Basically, it creates in the .eps the line:

%%BoundingBox: (atend)

However, epstopdf specifically says:

The case of "%%BoundingBox: (atend)" when input is not seekable (e.g., from a pipe) is not supported.

Now, the question is, why is the input not seekable, or is it a bug in epstopdf?

Also, would be interesting to check how previous versions of Matlab create the .eps with the same call.


The issue as identified by Christian Zietz of the epstopdf team:

I investigated a little further: It seems that the problem occurs only with MikTeX epstopdf and only if two things come together: "%%BoundingBox: (atend)" in the header of the EPS file and Unix-style line endings, meaning only LF and not CR+LF as it is customary in Windows.

I filed a bug report to Miktex.

  • I just converted your test file on linux with epstopdf script -- there were no errors
    – user31729
    Oct 21, 2014 at 2:26
  • Why no export directly to pdf from MatLab?
    – skpblack
    Oct 21, 2014 at 2:39
  • 1
    I run epstopdf in Windows and i got the same problem. I converted with Acrobat Distiller and no problem
    – skpblack
    Oct 21, 2014 at 2:44
  • @skpblack Cannot export directly in .pdf, not my choice. I do manage to open the file with ghostscript.
    – Oleg
    Oct 21, 2014 at 2:46
  • 1
    @skpblack: MATLAB has some cropping issues with PDF export, that's the reason for EPS.
    – Egon
    Oct 21, 2014 at 13:53

2 Answers 2


I ran into this as well on Windows. I used two solutions, the first one being portable and preferred.

Solution 1. Just read the eps file as text inside Matlab and replace any new lines \n by carriage returns + new lines \r\n. To make this portable, just use fwrite with the 'text' flag:

f = 'myplot.eps';
eps = fileread(f);
fd = fopen(f, 'wt');
fwrite(fd, eps);
system(['epstopdf ' f]);

Note the wt instead of just w in fopen(). This tells fopen() to write in text mode, which will replace any \n or \r\n\ with whatever the current OS is using, i.e. \r\n on Windows, \n on Linux etc.

Solution 2. The other, less portable way (and prone to font embedding issues) is to call Ghostscript directly to convert the .eps to .pdf and then pdfcrop (from Miktex) to crop to the bounding box for no white margins. You need to install Ghostscript for this, obviously.

gswin32c -sDEVICE=pdfwrite -o myplot.pdf myplot.eps
pdfcrop --hires --margins 0.25 myplot.pdf

This will produce mygraph-crop.pdf which you can use. You could also use the eps2pdf.pl script from the Xpdf binaries for Windows, but as far as I remember, that script also calls gswin32c. It may pass better/more complete options to gswin32c though (I haven't tried it). Note that you will (most probably) get warnings about font substitutions. The pdf should look fine, I haven't run into any visual issues. If it doesn't look fine then fixing those is a different animal (you'd have to either point Ghostscript to search more font paths probably via the -sFONTPATH= switch, or edit the font mapping file).

I just use Solution 1.



I am using R2014b as well. Saving a figure in matlab with the commandline using the 'print -depsc' or 'saveas('*.eps') commands results in the same eps-code as mentioned by previous posters, having the following Bounding Box properties in the *.eps file:

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: (MATLAB, The Mathworks, Inc. Version \(R2014b\). Operating System: Windows 7)
%%Title: filename.eps
%%CreationDate: 2015-01-12T18:05:47
%%Pages: (atend)
%%BoundingBox: (atend)
%%LanguageLevel: 3

But when I use the matlab gui to save the exact same figure as a *.eps i get a different behaviour. Now i get a *.eps file which is working with epstopdf in miktex:

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: (MATLAB, The Mathworks, Inc. Version \(R2014b\). Operating System: Windows 7)
%%Title: path/filename.eps
%%CreationDate: 2015-01-12T18:07:15
%%Pages: (atend)
%%BoundingBox: 0 0 403 302
%%LanguageLevel: 2

Update: when i use the hgexport function, i get a *.eps file which is working with epstopdf as well.

matlab code:
epsfig = hgexport('factorystyle');
epsfig.Format = 'eps';

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: (MATLAB, The Mathworks, Inc. Version \(R2014b\). Operating System: Windows 7)
%%Title: filename.eps
%%CreationDate: 2015-01-12T18:02:36
%%Pages: (atend)
%%BoundingBox: 0 0 403 302
%%LanguageLevel: 2

I found this solution in the mathworks community:http://de.mathworks.com/matlabcentral/answers/159509-eps-export-problems-in-r2014b

  • 1
    Welcome to TeX.SX! Perhaps you should elaborate on your answer and show us a screen shot?
    – user31729
    Jan 12, 2015 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.