[Ipe-discuss] How to Import Figure from Matlab to Ipe

Tim Hutt tdhutt at gmail.com
Tue Dec 2 11:47:13 CET 2008

This is the easiest way to save a figure as an ipe-editable PDF. Save the
following three matlab functions in your path. Then read them. You need
pdfcrop.pl and ActivePerl (if using windows) to crop the PDFs. Doing
SaveFigure('fig.pdf'); will save a cropped PDF that IPE can edit. You can
un-crop it by removing the unnamed stylesheets in IPE (although this did
crash IPE just now). Or you can comment out the CropPDF line.


function SaveFigure(filename, figure_handle)
% Save the figure to an ipe-compatible PDF.
% Filename is the name of the file to save it to (you can omit the .pdf
% extension if you like). figure_handle gives the figure to save. If
% omitted the current figure is used.

filename(find(filename == '\')) = '/';

if numel(filename >= 4) && strcmpi(filename(end-3:end), '.pdf')
    filename = filename(1:end-4);

if nargin < 2
    figure_handle = gcf;

saveas(figure_handle, filename, 'pdf');


function CropPDF(pdffile)
% Uses the pdfcrop program to crop the PDF.
% pdffile is the file name (without the extension) to crop. It is
% overwritten.

% You need the pdfcrop.pl script in the current directory (or you can
% modify the command line below to point to it), and a version of perl
% installed.
% pdfcrop.pl is available on ctan, and you can use ActivePerl on windows.

system(['perl pdfcrop.pl --verbose --margin 5 "' pdffile '.pdf"']);
movefile([pdffile '-crop.pdf'], [pdffile '.pdf']);


function PDFtoIPE(pdffile)
% Uses the PDFtoIPE program to convert the PDF to one IPE can edit.
% pdffile is the file name (without the extension) to convert. It is
% overwritten.

% Alter these paths to point to the location of your ipe programs.
pdftoipe = 'C:\Program Files\ipe-6.0pre30\bin\pdftoipe.exe';
ipetoipe = 'C:\Program Files\ipe-6.0pre30\bin\ipetoipe.exe';

system(['"' pdftoipe '" "' pdffile '.pdf" "' pdffile '.xml"']);
system(['"' ipetoipe '" -pdf "' pdffile '.xml" "' pdffile '.pdf"']);
delete([pdffile '.xml']);



Hope this helps.


More information about the Ipe-discuss mailing list