File Exchange

image thumbnail

save2pdf

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

25 Downloads

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 (2020). save2pdf (https://www.mathworks.com/matlabcentral/fileexchange/16179-save2pdf), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (44)

It's very helpful , Thanks

Hause Lin

María Caro

thank you

Lars Hagen

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.

Robert

Great function!

Vidak Kazic

Great function, finally found what I needed.

Vivas

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

Kartalb

Great tool, easy to use, does the job!

Thanks.

yoghy

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

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);

David

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

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

Tashfeen

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

Dan

Really helps when exporting a figure with transparency to PDF.

UEIH NEYUGN

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

Felix

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

Kermit

Very good !

Ariel Balter

Thanks!

Mark

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

Arnaud

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

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?

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

Richard Stephens

Excellent. Just what I was looking for.

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.

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?

Updates

1.0.0.0

Improved functioning of GUI dialog box.

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.

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