No BSD License  

4.90476
4.9 | 21 ratings Rate this file 131 Downloads (last 30 days) File Size: 2.14 KB File ID: #16179 Version: 1.0

save2pdf

by

Gabe Hoffmann (view profile)

 

30 Aug 2007 (Updated )

Saves a figure as a PDF as it appears on the screen.

| Watch this File

File Information
Description

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.

Acknowledgements

This file inspired Saveas2.M V1.1 (Sep 2009), Modeling And Design Analysis Of A Permanent Magnet Linear Synchronous Generator, and Save Figures Shortcut.

MATLAB release MATLAB 7.4 (R2007a)
Other requirements Has been tested on Windows (XP) and Linux (Fedora Core 7).
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (23)
21 Jun 2015 yoghy

yoghy (view profile)

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)
print(handle,'-dpdf',pdfFileName,sprintf('-r%d',dpi))

Somebody can help me, pleaseeeeeeee

Comment only
18 Jun 2015 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) ];
subplot(3,1,1);
plot(1:10);
title(Title);

subplot(3,1,2);
Title=['Word s=' num2str(sig) ];
plot(1:10);
title(Title);
save2pdf(saveTitle);

subplot(3,1,3);
Title=['s=' num2str(sig) ];
plot(1:10);
title(Title);
save2pdf(saveTitle);

09 Jan 2015 David

David (view profile)

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.

26 Aug 2014 victor

victor (view profile)

 
23 Jul 2014 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.

27 Jun 2014 Chen Chen

really nice function, saves a lot of trouble, thanks

13 Mar 2014 Stephan Koehler  
22 Aug 2013 Tashfeen

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

14 Aug 2013 Dan

Dan (view profile)

Really helps when exporting a figure with transparency to PDF.

05 Nov 2012 Sören Sieberling  
27 Jun 2012 UEIH NEYUGN

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

24 Jan 2012 Felix

Felix (view profile)

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

20 Oct 2011 Kermit

Kermit (view profile)

Very good !

24 Jan 2011 Ariel Balter

Thanks!

02 Jul 2010 Mark

Mark (view profile)

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

26 Apr 2010 Arnaud

Arnaud (view profile)

Easy to use and 100% useful for Latex users.
Thanks!

02 Mar 2010 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:
save2pdf('foo.pdf');

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?

Comment only
09 Oct 2009 Neil Dalchau

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

20 Oct 2008 Richard Stephens

Excellent. Just what I was looking for.

30 Aug 2008 A S

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.

15 Feb 2008 Tim Woolmer

Great stuff - just what I needed. Thanks!

14 Feb 2008 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.

05 Sep 2007 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?

Updates
24 Sep 2007

Added "Save As" dialog box, so that file name can be omitted in the function call, and ability to change the resolution of the output. Default resolution would be 150 dpi, but typical print-quality should be around 600 dpi.

Contact us