Code covered by the BSD License  

Highlights from
EPS Utility Toolbox

5.0

5.0 | 4 ratings Rate this file 113 Downloads (last 30 days) File Size: 187 KB File ID: #35429

EPS Utility Toolbox

by

 

02 Mar 2012 (Updated )

A set of functions to generate publisher-happy EPS images

| Watch this File

File Information
Description

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: http://partners.adobe.com/public/developer/ps
* 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 (www.ghostscript.com) 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 aip.org/peerx-press.org, use

   epswrite('fig.eps','EmbedFont','AddSymbol');

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(h,'VerticalAlignment','bottom','HorizontalAlignment','left','FontWeight','bold');
 set(gca,'position',[0.1 0 0.8 1]);
 axis off
 epswrite('logo','Size',[150 100]/200);
 eps2raster('logo','png','resolution',200,'deletesource','on')

Required Products MATLAB
MATLAB release MATLAB 8.3 (R2014a)
MATLAB Search Path
/
/fonts
/html
/src
Other requirements Ghostscript (9.05 or later) must be installed for some of the functions
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (44)
10 Oct 2014 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.

09 Oct 2014 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...

01 Oct 2014 Kesh Ikuma

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

30 Sep 2014 Sajjad Taghvaee

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

02 Jun 2014 Pete

@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: http://www.fontgeek.net/blog/?cat=7

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)

19 Apr 2014 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.

18 Apr 2014 Khawaja

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

09 Apr 2014 Jan Kappen

Thank you!

08 Apr 2014 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.

08 Apr 2014 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

14 Mar 2014 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.

12 Mar 2014 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

12 Mar 2014 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)
print(H,outfile,cmd{:});

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

Thanks in advance,

Junjie

13 Dec 2013 Michele

@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

12 Dec 2013 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".

12 Dec 2013 Michele

@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
'char'.

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

06 Dec 2013 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.

05 Dec 2013 Joseph

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?

12 Oct 2013 Werner

@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!

07 Oct 2013 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.

04 Oct 2013 Sourabh

I am trying to embed CMU Sans Serif fonts in the eps figures, trying to use epswrite:
epswrite(fHandle,fName,'EmbedFonts','all');
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
Output:
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.
...done.
STEP 3: Links to Ghostscript...
Ghostscript executable: "C:\Program Files (x86)\gs\gs8.63\bin\gswin32c.exe"
...done.
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

Sourabh

13 Sep 2013 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.

12 Sep 2013 Asmus

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?

05 Aug 2013 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.

24 Jul 2013 Conrad

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)
epsfixfonts(outfile,embedsymbol);

Error in MyProgramV1_060 (line 43)
epswrite(h,'fig.eps')

10 Jun 2013 Matteo

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

08 Jun 2013 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.

08 Jun 2013 Matteo

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

08 Jun 2013 Matteo

i figured out, very sorry ;-)
Matteo

08 Jun 2013 Matteo

Hello,
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)
epsembedfont(outfile,EmbedFontOptions{:},Symbol{:});

am i doing something wrongly?
Many thanks!

Matteo

07 May 2013 bart

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.

22 Apr 2013 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

22 Apr 2013 bart

Illustrator CS6 is complaining about missing font CMB10

epsembedfont('test6.eps','+Courier=>CMB10','+Helvetica=>CMB10','--Full');

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,
bart

27 Feb 2013 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 (http://www.mathworks.com/matlabcentral/fileexchange/38720) to build them yourself.

27 Feb 2013 bart

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

13 Jan 2013 Renwen Lin

It 's great!

But how to support chinese font?

11 Dec 2012 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.

11 Dec 2012 Chris

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!

30 Apr 2012 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).

30 Apr 2012 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?

25 Apr 2012 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.

25 Apr 2012 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.

20 Apr 2012 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

20 Apr 2012 Jens Munk Hansen

Dear Kesh Ikuma

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

epsfixbackground.m
??? 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

Updates
26 Apr 2013

- Added new functions: epssetup, epsfontpath, epsfontalias, psfontlist, epsgetbbox, epsgetfonts
- Gets postscript fonts directly from MATLAB installation directories.

- Default resolution in epswrite increased to 1000

26 Apr 2013

Added support for embedding of font subsetting (which can substantially reduces EPS file size).

Much thanks go to Ken Sharp on comp.lang.postscript newsgroup to help me sorting out the font subsetting issues.

26 Apr 2013

- New functions: epssetbgcolor.m, epscleancolordict.m
- Option enhancements in epswrite, epswrite, & eps2raster
- Bug fixes in eps2raster.m, epsembedfont.m, & epssetlinestyle.m

26 Apr 2013

-Removed misplaced file in v4
-Added Units option for epswrite
-Bug fixes
-FEX information update (+logo)

26 Apr 2013

* Added epssetbbox.m
* Fixed the bug reported by Jens Munk Hansen
* Option changes in epswrite.m, eps2raster.m, and epssetlinestyle.m

26 Apr 2013

Bug-fix release
* major bug in font embedding
* fixes MATLAB print bug that changes white line markers to black.

26 Apr 2013

* Added HTML helps in Help browser
* Minor bug fixes

26 Apr 2013

(v8) Bug fixes

26 Apr 2013

- bug fixes in epsfixfonts.m & type1subset.m
- separated private/getrscstr.m (generation of DSC Resource header elements)

26 Apr 2013

update

12 Mar 2014

Re-uploaded the correct v9 zip file

13 Mar 2014

* R2014A compatibility update
* Fixed 'Renderer' option value bug ('painter'->'painters')

09 Apr 2014

(Minor) bug fix - correctly produce error when EPS file name is not given.

10 Oct 2014

v12 - Bug fixes; validated to run with R2014b.

Contact us