Get from Ico-github-logo

Highlights from
export_fig

  • append_pdfs(varargin)
    APPEND_PDFS Appends/concatenates multiple PDF files
  • copyfig(fh)
    COPYFIG Create a copy of a figure, without changing the figure
  • eps2pdf(source, dest, cro...
    EPS2PDF Convert an eps file to pdf format using ghostscript
  • export_fig(varargin)
    EXPORT_FIG Exports figures suitable for publication
  • fix_lines(fname, fname2)
    FIX_LINES Improves the line style of eps files generated by print
  • ghostscript(cmd)
    GHOSTSCRIPT Calls a local GhostScript executable with the input command
  • im2gif(A, varargin)
    IM2GIF Convert a multiframe image to an animated GIF file
  • isolate_axes(ah, vis)
    ISOLATE_AXES Isolate the specified axes in a figure on their own
  • pdf2eps(source, dest)
    PDF2EPS Convert a pdf file to eps format using pdftops
  • pdftops(cmd)
    PDFTOPS Calls a local pdftops executable with the input command
  • print2array(fig, res, ren...
    PRINT2ARRAY Exports a figure to an image array
  • print2eps.m
  • user_string(string_name, ...
    USER_STRING Get/set a user specific string
  • using_hg2(fig)
    USING_HG2 Determine if the HG2 graphics pipeline is used
  • View all files
image thumbnail

export_fig

by

 

11 Apr 2009 (Updated )

Exports figures nicely to a number of vector & bitmap formats.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

pdf2eps(source, dest)
%PDF2EPS  Convert a pdf file to eps format using pdftops
%
% Examples:
%   pdf2eps source dest
%
% This function converts a pdf file to eps format.
%
% This function requires that you have pdftops, from the Xpdf suite of
% functions, installed on your system. This can be downloaded from:
% http://www.foolabs.com/xpdf  
%
%IN:
%   source - filename of the source pdf file to convert. The filename is
%            assumed to already have the extension ".pdf".
%   dest - filename of the destination eps file. The filename is assumed to
%          already have the extension ".eps".

% Copyright (C) Oliver Woodford 2009-2010

% Thanks to Aldebaro Klautau for reporting a bug when saving to
% non-existant directories.

function pdf2eps(source, dest)
% Construct the options string for pdftops
options = ['-q -paper match -eps -level2 "' source '" "' dest '"'];
% Convert to eps using pdftops
[status, message] = pdftops(options);
% Check for error
if status
    % Report error
    if isempty(message)
        error('Unable to generate eps. Check destination directory is writable.');
    else
        error(message);
    end
end
% Fix the DSC error created by pdftops
fid = fopen(dest, 'r+');
if fid == -1
    % Cannot open the file
    return
end
fgetl(fid); % Get the first line
str = fgetl(fid); % Get the second line
if strcmp(str(1:min(13, end)), '% Produced by')
    fseek(fid, -numel(str)-1, 'cof');
    fwrite(fid, '%'); % Turn ' ' into '%'
end
fclose(fid);
return

Contact us