File Exchange

image thumbnail

EPS Utility Toolbox

version 1.22 (187 KB) by Kesh Ikuma
A set of functions to generate publisher-happy EPS images


Updated 10 Oct 2014

View Version History

View License

EPS Utility Toolbox consists of several functions to enhance the outputs of the built-in EPS print engine. This toolbox is aimed to:
* Improve EPS standard compliance:
* Provide post-generation tweaks
Run epssetup.m first to set up the toolbox.
Toolbox Setup and Configuration
epssetup - Run this first to use this toolbox
epsfontpath - Get/set postscript font search path
epsfontalias - Get/set postscript font aliases
epsfontlist - Get the list of postscript fonts in the search path

EPS File Generation and Conversion
epswrite - Save figure as an EPS image (with fixes)
eps2raster - Convert EPS image to PNG, BMP, JPEG, or TIFF image (req. Ghostscript)

EPS File Manipulation
epsembedfont - Embed/de-embed postscript fonts (can embed subset or unencrypted font dictionaries)
epssetlinestyle - Set line styles (dotted, dashed, and dash-dot)
epssetbgcolor - Set background color (supports transparency)
epspreview - Add/remove TIFF preview (req. Ghostscript)
epssetbbox - Set bounding box position and size

EPS File Information
epsgetbbox - Get bounding box
epsgetfonts - Get fonts used
EPS Fix-It-Up Functions (called internally by epswrite.m)
epsfixfonts - Fix font related issues
epsfixbackground - Set figure and axes properties (especially Color)
epscleancolordict - Clean up RGB color definitions

Type 'help epsutil' to get the command window help. Indivisual m-files also include full command-window help text.

Some files requires Ghostscript ( to be installed on the computer.

To set resolution and size of the EPS image:

epswrite('fig.eps','Size',[2 4],'Resolution',600);

Size (= [width height]) are specified in inches and Resolution is specified in dots per inch (higher resolution increases the precision of object placements). Type "help epswrite" in Matlab for the full list of options.

For authors preparing manuscripts to, use


to embed Symbol font as their online submission system is not equipped with Symbol font (messes up all TeX characters).

Also, use both epswrite and eps2raster for those of us using pdftex to prepare LaTeX manuscripts for publishers who do not accept PDFs or PNGs. Executing

epswrite fig.eps
eps2raster fig.eps png

creates fig.eps and fig.png. This results in identical images in two formats and, IMO, also results in better quality images than directly printing from Matlab, especially with the antialiasing support of Ghostscript.

The submission logo was also created using this toolbox:

h = text(0,0,sprintf('EPS\nUtility\nToolbox'));
set(gca,'position',[0.1 0 0.8 1]);
axis off
epswrite('logo','Size',[150 100]/200);

Cite As

Kesh Ikuma (2021). EPS Utility Toolbox (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (48)


Hi There,

Thank you for this submission. It is very helpful. However, you may want to have a look at the commented section of the eps2raster.m file. You say that the 'Size' should be specified in pixels. However, on line 247, you compute the following:

size(:) = round(size*opts.Resolution);

This gives very large numbers for the size vector, because you multiply DPI by the size in pixels. The size should be specified in inches, so that line 147 returns the correct size in pixels. If you specify the size in pixels, (say, 150 x 250) and the resolution in DPI (300), you get very large numbers for the line 247 size value, which causes the computation to take astronomically long (I never let it finish) and give you the wrong resolution in the end.

Luckily, you don't have to change any code to keep it working, just change the help file :) Although, it would be nice to be able to specify the size in pixels.

Also, eps2raster errors out when you specify both non-zero dimensions for size. You may want to add an error message for that.

Thanks again!

Pol Henarejos

Dear Kesh. Thanks for this submission. It is fabulous. However I get an error when I execute 'epsembedfont', for a particular eps image. Not all images produce this error. I use the last version (v12).
Here is the trace:
Cell contents indices must be greater than 0

Error in getfonts (line 28)
FontData{I(n)} = imgdata(Istart(n):Iend(n));

Error in epsembedfont (line 85)
[AllFonts,EmbeddedFonts,EmbeddedFontData,imgdata] = getfonts(imgdata); % fontdata removed from imgdata

Error in printResult_LPI (line 105)
epsembedfont([fna '_cBER.eps']);


Matthew Taliaferro

I am using OSX 10.9.5 with MATLAB R2014A. When I run the set up file, I get an the following error after step 4:

STEP 4. Sets up Type 1 font search path and font alias table...
Error using rmpref (line 33)
GROUP and PREF must exist
Error in epssetup (line 102)

Any idea of why the set up is not working?

Noah Levine-Small

@Kesh, thanks for releasing the update! Great work.

Kesh Ikuma

@Noah - The latest version that I just uploaded should fix these issues. As for EPSCLEANCOLORDICT etc., these would be needed only on pre-R2014b. Mathworks completely changed around their EPS file structure, making these function completely obsolete. The latest EPSWRITE should automatically turns its calls to these postprocessing functions if you are using R2014b. Let me know if you run into other issues.

Noah Levine-Small

Hi Kesh. Thanks for the great submission. I get a few bugs running under R2014b. The first error arises in the nested function parse_input, since the params cell is never converted to structure if N==n0. Moving the line params = struct(params{:}); to before the if statement solves this. Then, EPSCLEANCOLORDICT, EPSFIXBACKGROUND and epssetbgcolor functions all give errors because regexp fails to match the strings you search for...Don't know know what to do about that one...

Kesh Ikuma

@Sajjad - No. This toolbox is not intended to edit EPS images beyond "fixing" a few known issues.

Sajjad Taghvaee

Is it possible to change the font size in an eps image using this toolbox?


@Chris - I had the same issue with wma_ fonts (matlab appear to have renamed their fonts at some point, and illustrator seems to demand that the specified font is installed on the system even if it is embedded in the file??).

I solved the problem by [using Mac OS X], by installing TTX and using it to rename my cmr10 and cmmi10 system fonts as mwa_cmr10 and mwa_cmmi10 (and then installing these new fonts). For step by step instructions, see:

I also ended up installing FontForge and replacing some of the glyphs in cmmi10, which were a bit wonky in my version (e.g., triangles instead of decimal points)

Kesh Ikuma

@Khawaja - EPS Utility Toolbox cannot help you with your problem. epsgetbbox just returns the bounding box that encapsulates all objects in an EPS image.

If they are simple shapes (i.e., groups of connected line segments), you can probably "decode" the postscript by writing your own purser. Your first step is to look at your .eps file in a text editor with the help of the PS standard, which is linked above in the toolbox description. Good luck.


Dear Fellows,
I need to extract width and length of each shape in .eps file.
But when I use epsgetbbox function, it gives me a 4 element vector.
But in my .eps file there are 7 shapes, how can extract Boundarybox or Width/ Length of each shape.
I shall be thankful to you for your help

Jan Kappen

Thank you!

Kesh Ikuma

@Jay - You are not calling epswrite correctly. You need to provide the file name for the EPS file as the first argument. E.g., epswrite('myplot.eps','Size',[10 15])

This being said, ESPWRITE should have produced an "official" error with your set of input arguments. I will put this check in the next release. Thanks.

Jan Kappen

Hey guys, I've got following problem:

epswrite('Size',[10 15])
120 if ~isempty(params.units)
Attempt to reference field of non-structure array.

Error in epswrite (line 120)
if ~isempty(params.units)

I only run epssetup and was trying to export a simple grahpic. I'm using matlab 2012b

Kesh Ikuma

@Junjie - Your fix is the correct one. I uploaded the fixed version just before your post, but the only change in the new version is what you suggested. Thanks.

Junjie Wang

it might because the new version have changed the keyword 'painter' to 'painters';

It fixed when I changed 'painter' to 'painters' in the programme.

Thanks for your great works

Junjie Wang

Hi Kesh,

I just wanted to use your toolbox, here I got a problem (might be quite stupid one, :)).I have Ghostscript installed and everything was successful when using epssetup, when I tried to use epswrite to generate my eps file, I kept getting the following error:
Error using inputcheck>LocalCheckOption (line 342)
Illegal option '-painter' given.

Error in inputcheck (line 86)
opIndex = LocalCheckOption( cur_arg, options );

Error in print (line 166)
[pj, devices, options ] = inputcheck( pj, inputargs{:} );

Error in epswrite (line 187)

Did I miss something there? BTW, I am running 64bit Windows 8.1

Thanks in advance,



@KeshIkuma: you're right, I cofused the "getdata.m" with the matlab intrinsic function, indeed I did not understand how it could work. Thank you very much for your help

Kesh Ikuma

@Michele - Have you extracted all the files? "getdata.m" is in "private" subfolder and should be accessible by "epssetlinestyle.m" as long as the "private" folder is in the same folder as "epssetlinestyle.m".


@KeshIkuma: thank you very much for the whole toolbox. However I'm trying to run the epssetlinestyle function but I receive this message:

??? Undefined function or method 'getdata' for input arguments of type

Error in ==> epssetlinestyle at 94
[epsdata,wmfdata,tifdata] = getdata(infile);

as input I'm using something like epssetlinestyle('myfile.eps','Param1',....)
where am I wrong ?

Thank you again

Kesh Ikuma

@Joseph - getgs() function is in the private folder within the distribution. Make sure that you've extracted all the files in the downloaded ZIP file, keeping the directory structure.


When I ran this function I got the following error:

Undefined function or variable 'getgs'.

Error in eps2raster (line 101)
gsexe = getgs();

Where do I get the 'getgs' function?


@KeshIkuma, you don't know how much I love you. I am in a hurry to finish my thesis, and matlab eps/pdf export was giving me so many issues. You just saved my life! Thank you so much.

Btw, if other people have the same issue that I was having, download this FEX and append: 'Size','screen' to your epswrite.

Thank you so much once again!

Kesh Ikuma

@Sourabh - I think I know what you are doing wrong here. Do not change the font in your MATLAB figure, leave it default Helvetica. Then, here are the steps:

1) Make sure that "CMU Sans Serif" is a postscript Type-1 font (.pfa or.pfb file). Take note of the location of the file.

2) Run epsfontlist and see if "CMU Sans Serif" is listed. If not, run epsfontpath and add the location of the font file to the EPS Utilities' path

3) Generate an EPS file using epswrite

4) Use epsembedfont with "+Helvetica=>CMUSansSerif" (or whatever as listed in epsfontlist) option

If this procedure does not work, please email me an example MATLAB figure and its EPS output to me directly, and we can sort it out.


I am trying to embed CMU Sans Serif fonts in the eps figures, trying to use epswrite:
But I am still seeing the default Courier type.
Looking at the eps file, I found the following fonts embedded:
Courier-SH-SS & HeaveneticaSH-SS
I have put the required pfb files in epsutil\fonts and re-run epssetup.m
STEP 2: Builds MEX functions...
decrypt.mexw64 successfully compiled and added to ...\MATLAB\epsutil\private.
encrypt.mexw64 successfully compiled and added to ...\MATLAB\epsutil\private.
STEP 3: Links to Ghostscript...
Ghostscript executable: "C:\Program Files (x86)\gs\gs8.63\bin\gswin32c.exe"
A list of fonts follows, but the fonts i want (CMU Sans Serif) is not in this list and neither is Heavenetica which is embedded in the eps file written by epswrite.
I am running MATLAB 2013a on win 7 64-bit
My objective is to integrate the figures into a LATEX manuscript, and I want consistent fonts. Please Help


Kesh Ikuma

@Asmus - Could you be more specific about the problem? Are you getting an error message or a faulty EPS output?

As far as I can tell (just tested this particular case with multi-screen Win7), negative position of a figure does not influence its EPS prints generated by epswrite.


Hi, thank you very much for this very encompassing and thorough toolbox.

I might have missed something altogether, but it seems like the tight bounding box option has some problems with negative paper sizes which occur when using matlab on multiple screens.

When the new paper position is being set in settightpos.m, there's nothing to account for this possibility.. Right? Or?

Kesh Ikuma

@Conrad - Thanks for reporting the error. However, it is very difficult for me to assess the exact nature of the issue without your EPS output file. If you are still interested, please email me your test output.

Moreover, if you download the latest version (which I just re-uploaded today), you can set the "Postprocessing" option to 'off' which should eliminate the error, and generate the EPS file.


Hi Kesh

Many thanks for developing this tool.

I just have a question because I experience an error when using this tool.

I am using a mac, so maybe this could be the problem.

Please would you let me know if I am using the tool incorrectly or if there is some way to fix the below problem?

I appreciate your time and thank you in advance!

My error is as follows:

Error using cell/setdiff>cellsetdiffR2012a (line 292)
Input A of class double and input B of class cell must be cell
arrays of strings, unless one is a string.

Error in cell/setdiff (line 84)
[varargout{1:nlhs}] = cellsetdiffR2012a(varargin{:});

Error in epsfixfonts (line 133)
NeededFonts = setdiff(AllFonts,EmbeddedFonts);

Error in epswrite (line 190)

Error in MyProgramV1_060 (line 43)


Hi Kesh,
i just sent you an email with an explanation and the files. Many many thanks for your time!!

Kesh Ikuma

@Matteo - Do you still get the error with getallstr()? If so, could you send me your figure, which produces the error?

As for the fonts "not well reproduced": Are you talking about the odd spacing? If so, that's the way it is for now, unfortunately.


actually the error is still present. ;-)
the new eps file is generated but the fonts are not well reproduced. many thanks for your time!


i figured out, very sorry ;-)


the program seems very useful, many thanks! while running it, i got this error:
Index exceeds matrix dimensions.

Error in getallstr (line 31)
M = [

Error in epsembedfont (line 170)
Strings = struct2cell(getallstr(imgdata));

Error in epsfixfonts (line 158)

am i doing something wrongly?
Many thanks!



I want to share the solution for the illustrator problem. I seems that the fonts are properly embedded but that illustrator expects that the used fonts are installed on the system, to avoid copyright issues with fonts.

Kesh Ikuma

@bart - Since I don't use/have Illustrator, I cannot confirm your issue. I see a potential reason for it though. Could you try this?

1. Open test6.eps in a text editor (you can simply use the MATLAB editor, "edit test6.eps")

2. On line 5 or so, you should see a line that starts with "%%DocumentNeededFonts:"

3. Replace "%%DocumentNeededFonts:" with "%%DocumentFonts:"

4. Save and open the EPS file in Illustrator

Let me know if this makes any difference. Thanks


Illustrator CS6 is complaining about missing font CMB10


The epsgetfonts states that CMB10 is embedded

I'm working is the x86 environment now.

My final goal is to embed the verdana font, but i don't succeed.

kind regards,

Kesh Ikuma

@bart, Yeah, Matlab (pre-R2013a) cannot build mex files in 64-bit environment. If you have MS Visual Studio/C++, you can use my other submission ( to build them yourself.


In Windows x64 I am unable to compile encrypt.cpp and decrypt.cpp.

Renwen Lin

It 's great!

But how to support chinese font?

Kesh Ikuma

@Chris - Thanks for your feedback. I'm surprised to hear that mwa_cmr10-SS could not be found in Illustrator. "-SS" indicates that a necessary subset of mwa_cmr10 font has been embedded in your EPS file.

Also, have you tried to use epsembedfont function with font substitution feature? For example, epsembedfont(epsfile,'+mwa_cmr10=>cmr10','--Subset'). You must first include the path to your cmr10 font using epsfontpath.

Christopher Thissen

Hi Kesh,

Excellent code. One issue I had was getting the eps fonts to be recognized in illustrator. Essentially, I was getting errors that mwa_cmr10-SS and similar fonts were missing. My system has cmr10 fonts installed, but not mwa_cmr10 fonts. I was able to resolve the issue by stripping off the mwa_ characters from the font name in the epsfixfonts.m function. Latex symbols appear properly in illustrator and preview now. I'm not sure if this is a specific issue with my system or if it is something more general, but I thought I'd let you know. Thanks again!

Kesh Ikuma

@Brian, Ha, I thought your name sounded familiar :)

@Jens, it sounds like that you are using "unsupported" LaTeX font on your MATLAB figure. While there are a several different ways to go, the easiest is the following:

1. Determine the missing font name and its PFB Type-1 font file (possibly already within your system or downloaded from CTAN server)

2. Place the PFB font file in "epsutil/fonts" subdirectory.

3. Run epswrite again with "EmbedFonts"="All" option.

Alternatively, you can use epsfontpath to add the folder with the PFB file to EPS Utility Toolbox's font search path.

I'd be more than happy to inspect (and play with) your EPS file if you can send it to me via email (see my FEX profile).

Brian Goss

This is actually on of @Jens files (this is Brian G. from PXPHelp)
I am just trying to open his files in Illustrator.
Here is the Font Problems error message.

SFRM1000: Font not found on the system; missing font has been substituted.
SFRM1200: Font not found on the system; missing font has been substituted.

It may be related to Windows computers not having the CM-Super font set installed. I am not certain.

Is there any other info I could provide?

Kesh Ikuma

@Brian, Would you be specific on how you generated your EPS figure? Is this with using {'EmbedFonts','all'} option? If the Illustrator continues to complain, would you tell me which fonts that it says its missing? Thanks.

Brian Goss

@Kesh and @Jens
I don't know is this will help, but when I open one of the figures in Illustrator CS4 I get the following font error.
SFRM1000: Font not found on the system; missing font has been substituted
SFRM1200: Font not found on the system; missing font has been substituted

Font substitution is close, but not perfect in this case.

Kesh Ikuma

@Jens, Thanks for pointing out the bug. Mathworks for whatever reason (compatibility?) uses different command to fill the figure background depending on Level 1 (deps) or Level 2 (deps2). I have fixed the bug, and the latest code will be upped on Monday. -Kesh

Jens Munk Hansen

Dear Kesh Ikuma

The tool compiled under linux, but I get the following error

??? Index exceeds matrix dimensions.

Error in ==> epsfixbackground at 71
figdim = str2num(tok{1}); %#ok

Temporary bugfix, for level 1 postscript

[I0,I1,tok] = regexp(imgdata,'\s+1\s+sg\s+0\s+0\s+(\d+\s+\d+)\s+PR\s+','start','end','tokens','once');

/Jens Munk Hansen

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: FIXPSLINESTYLE, export_fig

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!