source: MML/trunk/machine/SOLEIL/common/toolbox/export_fig/pdftops.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

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