4.66667

4.7 | 3 ratings Rate this file 175 downloads (last 30 days) File Size: 3.89 KB File ID: #22267

print_eps

by Oliver Woodford

 

28 Nov 2008 (Updated 14 Apr 2009)

Code covered by BSD License  

Save figures to high quality eps files with cropped borders and embedded fonts.

Download Now | Watch this File

File Information
Description

PLEASE NOTE - This function has now been superseded by EXPORT_FIG, which encompasses all its functionality plus some further functionality. This function will therefore no longer receive any support. EXPORT_FIG can be downloaded from:
http://www.mathworks.com/matlabcentral/fileexchange/23629

PRINT_EPS saves a figure to an eps file, with:
   - Figure borders cropped
   - Fonts embedded (as subsets)
   - Accurate vector graphics, compressed losslessly
   - High quality bitmap graphics, compressed lossily
   - Line dash lengths vary with line width (as on screen)
   - Grid lines given their own dot style, instead of dashed
   - No options to be set
 
PRINT_EPS requires only a target filename and an optional figure handle - there are no other options to be set. The output eps is exactly the size and layout of the figure on the screen. Additionally, line styles for dotted and dashed lines are improved for clarity, along with grid lines, resembling better those in the original figure. The function is perfect for generating eps figures for use in scientific publications.
 
PRINT_EPS uses ghostscript and pdftops (from the Xpdf package), so these must be installed on your system and the executables must be on your system's path. Get them from -
Ghostscript: http://www.ghostscript.com
Xpdf: http://www.foolabs.com/xpdf

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
savefig
This submission has inspired the following:
export_fig

MATLAB release MATLAB 7.5 (R2007b)
Other requirements Ghostscript, Xpdf
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
14 Dec 2008 Liang Li

Hey,

Thanks a lot for this function. This is exactly what I am looking for. However, I am using a window XP system and this function doesn't seem to work right. I guess it is because I did not make pdftops work right in win32. I went to the Xpdf website you mentioned above, download the precompiled binary package: Win32 (built with MSVC): xpdf-3.02pl2-win32.zip. I changed the directory in your function. However, system(cmd) returns a result of 1. Would you please give me some hints on what I should do? or it is just not for windows users?

Many thanks,

Liang

15 Dec 2008 Oliver Woodford

The function is written to work on all systems. I have used it on a Windows Vista system without any trouble.

16 Dec 2008 stone li

Would you please give me some hints about how to install the ghostscript and pdftops and set path for the compiler?

17 Dec 2008 Oliver Woodford

For Windows, download gs###w32.exe (where ### is a number, e.g. 863) from Sourceforge (follow the link at ghostscript.com), and extract it to the default location. Download the zip file named Xpdf-#.##pl2-win32.zip from http://www.foolabs.com/xpdf/download.html and extract the files in it to the folder
C:\Program Files\gs\gs#.##\bin (where #.## is a number) where Ghostscript was installed. Now put this folder on your system path, by following instructions at:
http://windowsitpro.com/article/articleid/48074/how-can-i-add-a-new-folder-to-my-system-path.html

09 Jan 2009 Le Page

Had some troubles to get it right, but then it produces what no other solution I tried managed to do... representing dotted/dashed lines properly. Thanks very much.

Comments/Questions:
- line 69: name = [cd filesep name];
If one indicates complete path names of the output .eps file, this line should apparently be taken out, otherwise it duplicates the path.

- I have a figure with grey colored axes (the background). It appears white in the .eps file when using this function. I also noticed it when using matlab functions. Only through exporting did I manage to get the right axes color. Any hints ?

- Also, line 70-72, in your comments, I guess you wanted to write pdftops instead of pstopdf ?

Thanks !

14 Jan 2009 wei feng

You may want to change line 69 to:
name = ['"', cd, filesep, name, '"']; % Add the path to the current directory
this way windows directories with spaces in them will work (such as c:\documents and settings\...

17 Jan 2009 Koray S. Erer

I must be making a mistake somewhere. When I try to open the created eps file, GSview issues the following DSC error: "This EPS file is missing the required %%BoundingBox" It nevertheless opens the file, but the figure is in wrong size and incorrectly cropped. In addition, originally italic Greek letters are not italic. Any help appreciated.

19 Jan 2009 Oliver Woodford

All the path issues mentioned have been fixed. The bbox error with gsview has been fixed.

The function uses the output of MATLAB's print, which automatically sets the background to white and italic Greek letters to non-italic (see http://www.mathworks.com/support/bugreports/details.html?rp=365825 for the latter).

20 Jan 2009 Andrej Vilhar

Thanks for the function! Unfortunately, I still have problems. I want the "čžš" letters to appear in my graphs in eps format and they still don't. I get an "`e" instead of "č" and an empty space " " instead of "ž".

I follow all the steps correctly and all the other things are OK. What am I missing? Thanks!

27 Jan 2009 Oliver Woodford

MATLAB's print can't handle some accents. Using the latex interpreter is a more reliable method for including them, e.g.
title('H\'{e}ll\"{o} \v{c}\v{z}\v{s}', 'Interpreter', 'Latex')

09 Feb 2009 Andres Leon

HELLO, I FOLLOW THIS STEPS:

For Windows, download gs###w32.exe (where ### is a number, e.g. 863) from Sourceforge ........on your system path, by following instructions at:
http://windowsitpro.com/article/articleid/48074/how-can-i-add-a-new-folder-to-my-system-path.html

THEN I TYPE ON MATLAB, GETTING THE FOLLOW ERROR MESSAGE:

>> print_eps('PQ')
Error: /configurationerror in --setpagedevice--
Additional information: [/PageSize [-415 -311]]
Operand stack:
   --nostringval-- (%%BoundingBox: 515 553 100 242) --dict:1/2(ro)(G)-- --nostringval-- --nostringval-- (%%BoundingBox: 515 553 100 242) 1 515 553 --dict:1/1(L)--
Execution stack:
   %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1905 1 3 %oparray_pop 1904 1 3 %oparray_pop --nostringval-- 1888 1 3 %oparray_pop 1771 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- %ztokenexec_continue (scanner state) --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- 1873 10 3 %oparray_pop --nostringval-- --nostringval-- --dict:8/10(L)-- --nostringval-- 4 %dict_continue
Dictionary stack:
   --dict:1152/1684(ro)(G)-- --dict:0/20(G)-- --dict:74/200(L)--
Current allocation mode is local
Current file position is 356
GPL Ghostscript 8.63: Unrecoverable error, exit code 1

WHERE MY FILE IS PQ.eps. PLEASE I NEED HELP TO SOLVE THIS ERROR. THANK A LOT

08 Apr 2009 Kelley Sullivan

I have the same problem as Andres. Any solution? Thanks.

09 Apr 2009 Oliver Woodford

Apparently a system restart can fix some ghostscript problems. (Thanks, Kelley).

Please login to add a comment or rating.
Updates
01 Dec 2008

Avoid changing figure position units

11 Dec 2008

Fix line styles to look more like those on screen

11 Dec 2008

Fix line styles, and set grid lines to a different style from dotted lines

11 Dec 2008

Improve finding of grid lines to update line style

12 Dec 2008

Change dash length with line width

15 Dec 2008

Improved line styles for thinner lines

19 Jan 2009

Allow full and relative paths. Allow paths with spaces in. Fix distance between grid line dots. Avoid bbox error with gsview.

09 Feb 2009

Bug fix to fix_lines subfunction

12 Feb 2009

Pass figure handle to print as a double, not a string. Allow printing of gui elements.

08 Apr 2009

Reduce memory footprint to allow conversion of larger files

14 Apr 2009

Supereseded by EXPORT_FIG

Tag Activity for this File
Tag Applied By Date/Time
data export Oliver Woodford 01 Dec 2008 15:12:59
export Oliver Woodford 01 Dec 2008 15:12:59
figure Oliver Woodford 01 Dec 2008 15:12:59
export figure Oliver Woodford 01 Dec 2008 15:12:59
eps Oliver Woodford 01 Dec 2008 15:12:59
embed Oliver Woodford 01 Dec 2008 15:12:59
fonts Oliver Woodford 01 Dec 2008 15:12:59
embed fonts Oliver Woodford 01 Dec 2008 15:12:59
print Oliver Woodford 01 Dec 2008 15:12:59
save Oliver Woodford 01 Dec 2008 15:12:59
vector graphics Oliver Woodford 01 Dec 2008 15:12:59
data import Cristina McIntire 12 Dec 2008 15:32:32
line style Oliver Woodford 16 Dec 2008 16:43:46
dashed Oliver Woodford 16 Dec 2008 16:43:46
dotted Oliver Woodford 16 Dec 2008 16:43:46
dashed Koray S. Erer 17 Jan 2009 13:25:29
dashed Mattias 09 Mar 2009 04:55:45
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com