View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.7 | 18 ratings Rate this file 43 Downloads (last 30 days) File Size: 16.9 KB File ID: #19516 Version:



Richard Quist (view profile)


09 Apr 2008 (Updated )

Convert PostScript file to PDF using Ghostscript; can generate multi-page PDF files.

| Watch this File

File Information

Converts a postscript file into PDF. The resulting PDF file will contain one page for each page defined in the postscript file, so a multi-page postscript file, like those generated by using the '-append' option of MATLAB's print command, can be used to generate a multi-page PDF file.
Works with the version of Ghostscript shipped with MATLAB, if found, or with a user-specified version.

Also works with older MATLAB versions, such as R2006b.


This file inspired Gui2pdf.

MATLAB release MATLAB 7.6 (R2008a)
Other requirements Deployed applications require a separate installation of Ghostscript.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (29)
13 Sep 2016 K K

K K (view profile)

I was able to get this working in 2016a by:
* Installing ghostscript from
* using the 'gscommand' and 'gslibpath' arguments to ps2pdf. I get a warning about not specifying 'gsfontpath' but it still works fine.

Note that I also needed to add a '-fillpage' to my print command to get the figures to stay full page. I had just been using 'orient landscape' but some defaults seem to have changed.

08 Sep 2016 Alexander Walzl

Hi @ all
First, i would like to thank you for this well working program.

I use it in connection with the gui2pdf app and gs9.19. Only one question is left. Is there a opportunity to increase the image quality/resolution of the images embedded into the pdf?

Because function-plots are very rough and blurred. Is there a way to fix it?


23 Jun 2016 David Bryson

@ Neal Connardy, i see that builtin fails in 2016(a) any advice?

Comment only
23 May 2016 Neal Conrardy

No more Ghostscript for 2016A?

Comment only
14 Oct 2015 KaBra

KaBra (view profile)

Great program, thanks. Unfortunately, I can’t make it run on Matlab 2015b. I do get the following error message:

“Error using f_ps2pdf>LocalParseArgs (line 329)
Can not find Ghostscript program in MATLAB

Error in f_ps2pdf (line 112)
gsData = LocalParseArgs(varargin{:});”

Any suggestions what I could do? I read the post of Neal from 08 Jan 2015, but this does not seem to work in Matlab 2015b or lets say I do not have a folder in “sys” that is called “extern”.

Comment only
27 Feb 2015 Miriam

Miriam (view profile)

To get it to work on my Mac, I changed line 297 to ghostDir = fullfile(matlabroot, 'sys', 'extern', 'maci64', 'ghostscript')`

08 Jan 2015 Neal

Neal (view profile)

This does not work on release R2014b. The path to the ghostscript files has been moved.
Line 297 requires updating.
ghostDir = fullfile(matlabroot, 'sys', 'gs8x' );
ghostDir = fullfile(matlabroot, 'sys', 'extern', 'win64', 'ghostscript' );

28 Apr 2012 Andrea Gentilini

Fantastic tool. Would be even better if it allowed user to control for portrait or landscape orientation. I saw other users have requested the same. Thanks, Andrea

09 Nov 2011 suraj

suraj (view profile)

great tool anyday!! need help with minor issue. when I have a figure with rotated xticklabels and I append it to a ps file which I make into a pdf using ps2pdf, the figure gets rotated so that the text is now horizontal. any way to force orientation to landscape while writing to pdf? thanks.

Comment only
02 Nov 2011 David Berns

When i run this program in a folder where the path has a parentheses in it, e.g. C:\DriveName\User(David)\, this program produces the following error: Problem converting PostScript. System returned error: -13.Unrecoverable error: limitcheck in .putdeviceprops.

I indeed tried the program in a folder whose path doesn't have a parentheses and it seems to work fine.


Comment only
04 May 2011 Michael Teo

Oh, i found the solution.

I have to set the MATLAB print to landscape by

orient landscape;

Comment only
04 May 2011 Michael Teo

Can i print the PDF to A4 landscape?

28 Mar 2011 Robert Cumming

Robert Cumming (view profile)

18 Mar 2011 Rossella

Great function! Really useful.
Is there a way to set the PDF paper to horizontal (either letter or A4)? I tried each possible gspapersize, but I didn't find anyone working fine in this case.

22 Jul 2010 Esben Vedel-Larsen

Very nice file, I have found it very usefull. I had the same problem with the version, but the newest file solved it, Thank you!

Comment only
22 Jul 2010 Esben Vedel-Larsen

20 Jul 2010 Felix

Felix (view profile)

Any way to include ps2pdf.m and ghostscript in a compiled application?

Comment only
22 Apr 2010 K K

K K (view profile)

Yes, I had the same problem after upgrading to 7.10. I just commented out the if-else starting on line 289, and it will just default to using the internal ghostscript for now.

Comment only
09 Apr 2010 Can Baran

I think this is pretty well written. One thing to comment:
I just upgraded to 2010a, the line at 287:
if str2double(v.Version) < 7.4
v.version is = 7.10 which is bigger than 7.4 but str2double of 7.10 is smaller than 7.4
So, there might be a better way of dealing with this than the one i am about to write:
compare the first digit(s) before the point, if they are the same, compare the digit(s) after the point. I think this is a still pretty damn solid .m file, I wish i could give 4.5 stars.

04 Feb 2010 Per Bröms

Very nice. This work very good for me.

I found two bugs thou.

1) You need to put " (double quote) around the Ghostscript input file name. If you have space chars in the path e.g. "\\server\directory with space in the name\" it will crash otherwise. So line 123 and 125 need to be modified.

New 123- [s, r] = gsData.cmd(['@' gsData.responseFile], ['"' gsData.psFile '"'], gsDebug);

New 125- [s, r] = system([gsData.cmd ' @' gsData.responseFile ' "' gsData.psFile '"']);

2) To work with really old version of MATLAB, like R14, you need to remove the () after Local_GetOldGhostscript(); in line 288

New 288- [gsCmd, ghostDir] = Local_GetOldGhostscript;

Now it work on R14 and with all directory names.
Also tested on 2006b.


Comment only
04 Feb 2010 Per Bröms

14 Oct 2009 Andrew Bytheway

Great idea! I did experience problems when using this script in a deployed application (R2009a). The built-in version of Ghostscript doesn't work in deployed applications. It returns the following error:
??? Undefined function or method 'gscript' for input arguments of type 'char'.
Clearly it is failing to recognize the call to gscript altough the function handle was created correctly, and the needed mexw32 file is distributed with the MCR v7.10

Any ideas ???

07 Jan 2009 Tom Mat

The Title (push Ctrl+Shift+D in Acrobat) of the pdf files, is the name and path of the ps File. It would be good to have an option to avoid this...

Comment only
07 Jan 2009 Tom Mat

10 Sep 2008 Mat K

Great Script, options to set Author, Title, Subject etc. would make it superior...

22 Aug 2008 Pat Murray

Excellent, exactly what I needed, saves me a time-consuming step for my project.


04 Aug 2008 Naveen K

Perfect. Exactly what i needed. Many thanks Richard.

01 Jul 2008 Pablo Pablo

Excelent script.
Tested on Matlab2008a
Thanks a lot.

09 Apr 2008 Yuri Kotliarov

It's amazing! I just started looking for this feature and found this function dated TODAY. Tested on 2007b. Works like a charm. Thanks a lot!

14 Apr 2008

added screenshot

21 Apr 2008

added option to delete input postscript file after creating pdf file. Default is to NOT delete the input ps file

16 Jun 2010 1.7

Added check for deployed applications, plus some bug fixes and minor documentation updates.

01 Sep 2016

Updated license

Contact us