Home > data-vis > supporting_functions > export_fig > pdf2eps.m

pdf2eps

PURPOSE ^

PDF2EPS Convert a pdf file to eps format using pdftops

SYNOPSIS ^

function pdf2eps(source, dest)

DESCRIPTION ^

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".

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %PDF2EPS  Convert a pdf file to eps format using pdftops
0002 %
0003 % Examples:
0004 %   pdf2eps source dest
0005 %
0006 % This function converts a pdf file to eps format.
0007 %
0008 % This function requires that you have pdftops, from the Xpdf suite of
0009 % functions, installed on your system. This can be downloaded from:
0010 % http://www.foolabs.com/xpdf
0011 %
0012 %IN:
0013 %   source - filename of the source pdf file to convert. The filename is
0014 %            assumed to already have the extension ".pdf".
0015 %   dest - filename of the destination eps file. The filename is assumed to
0016 %          already have the extension ".eps".
0017 
0018 % Copyright (C) Oliver Woodford 2009-2010
0019 
0020 % Thanks to Aldebaro Klautau for reporting a bug when saving to
0021 % non-existant directories.
0022 
0023 function pdf2eps(source, dest)
0024 % Construct the options string for pdftops
0025 options = ['-q -paper match -eps -level2 "' source '" "' dest '"'];
0026 % Convert to eps using pdftops
0027 [status, message] = pdftops(options);
0028 % Check for error
0029 if status
0030     % Report error
0031     if isempty(message)
0032         error('Unable to generate eps. Check destination directory is writable.');
0033     else
0034         error(message);
0035     end
0036 end
0037 % Fix the DSC error created by pdftops
0038 fid = fopen(dest, 'r+');
0039 if fid == -1
0040     % Cannot open the file
0041     return
0042 end
0043 fgetl(fid); % Get the first line
0044 str = fgetl(fid); % Get the second line
0045 if strcmp(str(1:min(13, end)), '% Produced by')
0046     fseek(fid, -numel(str)-1, 'cof');
0047     fwrite(fid, '%'); % Turn ' ' into '%'
0048 end
0049 fclose(fid);
0050 end
0051

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005