Save Matlab Figures to pdf / convert eps files to pdf
In Matlab saving a figure as a pdf results in a rather bad quality. It is better to save the figure as .eps and convert it to .pdf, e.g. in Linux via the terminal tool
epstopdf File.eps
NOTE, especially if the .eps file is in landscape orientation, the terminal tool ps2pdf does not work properly and cuts off pdfs in portrait orientation.
If you have problems that the .eps file does not turn out in the correct orientation and size or you want to specify the size of the output, try in matlab
set(gcf,'PaperPosition', [[0.25 2.5 14.0 8.0]]);
This example sets the figure size to a width of 14.0 inches and height of 8.0 inches, with the origin of the figure positioned 0.25 inches from the left edge of the paper and 2.5 inches from the bottom edge.
The 'papersize' does not play an import role. I just set it larger as 14.0 and 8.0, so e.g.
set(gcf,'papersize',[16 16])
The last two numbers of 'PaperPosition' determine the size of the eps.
To print the .fig to .eps, use
print('-depsc', '/path/to/file/filename.eps'); % gray eps print('-depsc2', '/path/to/file/filename.eps'); % color eps
Alternatively you can use the saveas command
saveas(gcf,[MyPATH,MyIMG,'_grid.eps'],'psc2') % color eps saveas(gcf,[MyPATH,MyIMG,'_grid.eps'],'eps') % gray eps
You can use following line for converting eps to pdf from within a .m file (requires the linux tool epstopdf to be installed).
system(sprintf('epstopdf %s.eps',filename));
Add new comment