source: issm/trunk-jpl/externalpackages/export_fig/pdftops.m@ 19993

Last change on this file since 19993 was 19993, checked in by seroussi, 9 years ago

BUG: reverting back to old export_fig (too many problems)

File size: 3.1 KB
Line 
1function varargout = pdftops(cmd)
2%PDFTOPS Calls a local pdftops executable with the input command
3%
4% Example:
5% [status result] = pdftops(cmd)
6%
7% Attempts to locate a pdftops executable, finally asking the user to
8% specify the directory pdftops was installed into. The resulting path is
9% stored for future reference.
10%
11% Once found, the executable is called with the input command string.
12%
13% This function requires that you have pdftops (from the Xpdf package)
14% installed on your system. You can download this from:
15% http://www.foolabs.com/xpdf
16%
17% IN:
18% cmd - Command string to be passed into pdftops.
19%
20% OUT:
21% status - 0 iff command ran without problem.
22% result - Output from pdftops.
23
24% Copyright: Oliver Woodford, 2009-2010
25
26% Thanks to Jonas Dorn for the fix for the title of the uigetdir window on
27% Mac OS.
28% Thanks to Christoph Hertel for pointing out a bug in check_xpdf_path
29% under linux.
30% 23/01/2014 - Add full path to pdftops.txt in warning.
31
32% Call pdftops
33[varargout{1:nargout}] = system(sprintf('"%s" %s', xpdf_path, cmd));
34end
35
36function path_ = xpdf_path
37% Return a valid path
38% Start with the currently set path
39path_ = user_string('pdftops');
40% Check the path works
41if check_xpdf_path(path_)
42 return
43end
44% Check whether the binary is on the path
45if ispc
46 bin = 'pdftops.exe';
47else
48 bin = 'pdftops';
49end
50if check_store_xpdf_path(bin)
51 path_ = bin;
52 return
53end
54% Search the obvious places
55if ispc
56 path_ = 'C:\Program Files\xpdf\pdftops.exe';
57else
58 path_ = '/usr/local/bin/pdftops';
59end
60if check_store_xpdf_path(path_)
61 return
62end
63% Ask the user to enter the path
64while 1
65 if strncmp(computer,'MAC',3) % Is a Mac
66 % Give separate warning as the uigetdir dialogue box doesn't have a
67 % title
68 uiwait(warndlg('Pdftops not found. Please locate the program, or install xpdf-tools from http://users.phg-online.de/tk/MOSXS/.'))
69 end
70 base = uigetdir('/', 'Pdftops not found. Please locate the program.');
71 if isequal(base, 0)
72 % User hit cancel or closed window
73 break;
74 end
75 base = [base filesep];
76 bin_dir = {'', ['bin' filesep], ['lib' filesep]};
77 for a = 1:numel(bin_dir)
78 path_ = [base bin_dir{a} bin];
79 if exist(path_, 'file') == 2
80 break;
81 end
82 end
83 if check_store_xpdf_path(path_)
84 return
85 end
86end
87error('pdftops executable not found.');
88end
89
90function good = check_store_xpdf_path(path_)
91% Check the path is valid
92good = check_xpdf_path(path_);
93if ~good
94 return
95end
96% Update the current default path to the path found
97if ~user_string('pdftops', path_)
98 warning('Path to pdftops executable could not be saved. Enter it manually in %s.', fullfile(fileparts(which('user_string.m')), '.ignore', 'pdftops.txt'));
99 return
100end
101end
102
103function good = check_xpdf_path(path_)
104% Check the path is valid
105[good, message] = system(sprintf('"%s" -h', path_));
106% system returns good = 1 even when the command runs
107% Look for something distinct in the help text
108good = ~isempty(strfind(message, 'PostScript'));
109end
Note: See TracBrowser for help on using the repository browser.