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

Last change on this file since 14174 was 14174, checked in by Mathieu Morlighem, 12 years ago

CHG: updated export_fig

File size: 3.0 KB
RevLine 
[7182]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
[14174]35function path_ = xpdf_path
[7182]36% Return a valid path
37% Start with the currently set path
[14174]38path_ = user_string('pdftops');
[7182]39% Check the path works
[14174]40if check_xpdf_path(path_)
[7182]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)
[14174]50 path_ = bin;
[7182]51 return
52end
53% Search the obvious places
54if ispc
[14174]55 path_ = 'C:\Program Files\xpdf\pdftops.exe';
[7182]56else
[14174]57 path_ = '/usr/local/bin/pdftops';
[7182]58end
[14174]59if check_store_xpdf_path(path_)
[7182]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)
[14174]77 path_ = [base bin_dir{a} bin];
78 if exist(path_, 'file') == 2
[7182]79 break;
80 end
81 end
[14174]82 if check_store_xpdf_path(path_)
[7182]83 return
84 end
85end
86error('pdftops executable not found.');
87
[14174]88function good = check_store_xpdf_path(path_)
[7182]89% Check the path is valid
[14174]90good = check_xpdf_path(path_);
[7182]91if ~good
92 return
93end
94% Update the current default path to the path found
[14174]95if ~user_string('pdftops', path_)
[10635]96 warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.');
[7182]97 return
98end
99return
100
[14174]101function good = check_xpdf_path(path_)
[7182]102% Check the path is valid
[14174]103[good message] = system(sprintf('"%s" -h', path_));
[7182]104% system returns good = 1 even when the command runs
105% Look for something distinct in the help text
106good = ~isempty(strfind(message, 'PostScript'));
[10635]107return
Note: See TracBrowser for help on using the repository browser.