ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pdf2eps.m
Go to the documentation of this file.
1%PDF2EPS Convert a pdf file to eps format using pdftops
2%
3% Examples:
4% pdf2eps source dest
5%
6% This function converts a pdf file to eps format.
7%
8% This function requires that you have pdftops, from the Xpdf suite of
9% functions, installed on your system. This can be downloaded from:
10% http://xpdfreader.com
11%
12% Inputs:
13% source - filename of the source pdf file to convert. The filename is
14% assumed to already have the extension ".pdf".
15% dest - filename of the destination eps file. The filename is assumed to
16% already have the extension ".eps".
17
18% Copyright (C) Oliver Woodford 2009-2010, Yair Altman 2015-
19
20% Thanks to Aldebaro Klautau for reporting a bug when saving to
21% non-existant directories.
22
23% 22/09/2018 - Xpdf website changed to xpdfreader.com
24
25function pdf2eps(source, dest)
26 % Construct the options string for pdftops
27 options = ['-q -paper match -eps -level2 "' source '" "' dest '"'];
28
29 % Convert to eps using pdftops
30 [status, message] = pdftops(options);
31
32 % Check for error
33 if status
34 % Report error
35 if isempty(message)
36 error('Unable to generate eps. Check destination directory is writable.');
37 else
38 error(message);
39 end
40 end
41
42 % Fix the DSC error created by pdftops
43 fid = fopen(dest, 'r+');
44 if fid == -1
45 % Cannot open the file
46 return
47 end
48 fgetl(fid); % Get the first line
49 str = fgetl(fid); % Get the second line
50 if strcmp(str(1:min(13, end)), '% Produced by')
51 fseek(fid, -numel(str)-1, 'cof');
52 fwrite(fid, '%'); % Turn ' ' into '%'
53 end
54 fclose(fid);
55end
function pdf2eps(in source, in dest)
function pdftops(in cmd)