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

Last change on this file since 10937 was 10635, checked in by Mathieu Morlighem, 13 years ago

New export_fig bug with text color fixed

File size: 3.0 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
31% Call pdftops
32[varargout{1:nargout}] = system(sprintf('"%s" %s', xpdf_path, cmd));
33return
34
35function path = xpdf_path
36% Return a valid path
37% Start with the currently set path
38path = user_string('pdftops');
39% Check the path works
40if check_xpdf_path(path)
41 return
42end
43% Check whether the binary is on the path
44if ispc
45 bin = 'pdftops.exe';
46else
47 bin = 'pdftops';
48end
49if check_store_xpdf_path(bin)
50 path = bin;
51 return
52end
53% Search the obvious places
54if ispc
55 path = 'C:\Program Files\xpdf\pdftops.exe';
56else
57 path = '/usr/local/bin/pdftops';
58end
59if check_store_xpdf_path(path)
60 return
61end
62% Ask the user to enter the path
63while 1
64 if strncmp(computer,'MAC',3) % Is a Mac
65 % Give separate warning as the uigetdir dialogue box doesn't have a
66 % title
67 uiwait(warndlg('Pdftops not found. Please locate the program, or install xpdf-tools from http://users.phg-online.de/tk/MOSXS/.'))
68 end
69 base = uigetdir('/', 'Pdftops not found. Please locate the program.');
70 if isequal(base, 0)
71 % User hit cancel or closed window
72 break;
73 end
74 base = [base filesep];
75 bin_dir = {'', ['bin' filesep], ['lib' filesep]};
76 for a = 1:numel(bin_dir)
77 path = [base bin_dir{a} bin];
78 if exist(path, 'file') == 2
79 break;
80 end
81 end
82 if check_store_xpdf_path(path)
83 return
84 end
85end
86error('pdftops executable not found.');
87
88function good = check_store_xpdf_path(path)
89% Check the path is valid
90good = check_xpdf_path(path);
91if ~good
92 return
93end
94% Update the current default path to the path found
95if ~user_string('pdftops', path)
96 warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.');
97 return
98end
99return
100
101function good = check_xpdf_path(path)
102% Check the path is valid
103[good message] = system(sprintf('"%s" -h', path));
104% system returns good = 1 even when the command runs
105% Look for something distinct in the help text
106good = ~isempty(strfind(message, 'PostScript'));
107return
Note: See TracBrowser for help on using the repository browser.