File Exchange

image thumbnail


version (969 Bytes) by Gabe Hoffmann
Saves a figure as a PDF as it appears on the screen.


Updated 15 Jan 2008

No License

SAVE2PDF saves a figure as a PDF as it appears on the screen. SAVE2PDF is stand-alone and simple--it does not require a separate installation of ghostscript. It saves figures as they appear on the screen, with the correct page size. It has the option to change the resolution to be print-quality.

SAVE2PDF is particularly useful for LaTex users who want to generate PDFs to include when compiling with pdftex. The vector art information is preserved.

This function simply augments the built in print-to-pdf functionality of Matlab by resizing the output PDF and shifting the displayed plot.

Cite As

Gabe Hoffmann (2021). save2pdf (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (46)


What I was looking for... direct for Latex


It's very helpful , Thanks

Hause Lin

María Caro


thank you

ashish mishra

Matthew Kelly

Frank Hogervorst

Lars Hagen

Jochen Bregar

Asier Mariscal

Changjie Guan

It is what I'm looking for. Very helpful! Thank you.

j o

Never mind my previous rating, I used the wrong renderer :)

j o

Does not save pdfs with transparency and vectors, like the built-in export to pdf so no reason to use this.

amos li

good to convert to pdf file

Paul Towns

That's absolutely amazing. I've searched on the web for a long time before I found this one. Solve my problem perfectly.


Great function!

Vidak Kazic

Great function, finally found what I needed.


Any ideas to make it work with bode plots as well. Presently, the x axis labels get messed up.


Great tool, easy to use, does the job!



Hello, I am new in this type of graphs. This code did not work in my graph. I have the next error message:
Error using validateHandleToPrint (line 36)
Can only print one page at a time.

Error in validate (line 17)
pj = validateHandleToPrint(pj);

Error in print (line 201)
pj = validate( pj );

Error in save2pdf (line 60)

Somebody can help me, pleaseeeeeeee

Leo Simon

Love the program, but came across a bug, at least on my machine. Don't seem to be able to upload a pdf file, but hopefully if you run the code below you'll see the problem. In the title for the first subplot, save2pdf throws in a space that's not present in either the matlab figure or the pdf generated by matlab's print function. In the second and third subplot the modified titles don't have the same problem. Really wierd!

sig = 0;
saveTitle = 'save2pdfBug.pdf';
Title=['Word s_j=' num2str(sig) ];

Title=['Word s=' num2str(sig) ];

Title=['s=' num2str(sig) ];


This is amazing! I've been waiting my whole Matlab life for this. Saving to a pdf in Matlab is normally rife with difficulties, and this makes the process very simple.

Victor Amelkin

Giacomo Ciani

Very handy function, thanks. Just a suggestion: force the 'paperOrientation' property to 'landscape' (that is usually the default); if it has been changed to 'landscape', the function will not produce the expected output.

Chen Chen

really nice function, saves a lot of trouble, thanks

Stephan Koehler


Excellent! One of the best utility I found on this forum.


Really helps when exporting a figure with transparency to PDF.

Sören Sieberling


Great, I was able to adapt to other extension, i.e. pdf, eps ...


Thank you very much, searched in so many forums to solve exactly this problem!


Very good !

Ariel Balter



Great Job. Works a charm -- has probably saved me several hours of frustration.


Easy to use and 100% useful for Latex users.

Koos Spee

I have got one question regarding dimensions of the saved file.

When I set figure position / size with:
set(gcf, 'Position', [400 400 600 100])
and then apply:

The dimensions of the image will be 450x75

Same with other values of width & height... al get resized to 75%

Does anybody know why this happens?

Neil Dalchau

Great function, provided perfect solution first time around!
Many thanks

Richard Stephens

Excellent. Just what I was looking for.


Works good and helps a lot with mass-pdf-graph-generation ... pdf2ps in linux doesn't generate vectorized .ps from these pdfs, but that's not Gabe's fault.

Tim Woolmer

Great stuff - just what I needed. Thanks!

Nathan Miller

Works great and I don't have to manually crop the pdfs.

The only problem I have is that the legend output is different whether you use the command line 'print' or select "save as" from the figure menu. Using 'print', the legend background color is lost and the black outline shows up even when set to white. However, this is a matlab bug, not this code's problem.

Dan Kominsky

Nice and does what it says. But what I'm really interested in is how to save multiple figures to a multi-page pdf without ghostscript. Any thoughts?

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

Community Treasure Hunt

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

Start Hunting!