1 | function 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));
|
---|
33 | return
|
---|
34 |
|
---|
35 | function path = xpdf_path
|
---|
36 | % Return a valid path
|
---|
37 | % Start with the currently set path
|
---|
38 | path = user_string('pdftops');
|
---|
39 | % Check the path works
|
---|
40 | if check_xpdf_path(path)
|
---|
41 | return
|
---|
42 | end
|
---|
43 | % Check whether the binary is on the path
|
---|
44 | if ispc
|
---|
45 | bin = 'pdftops.exe';
|
---|
46 | else
|
---|
47 | bin = 'pdftops';
|
---|
48 | end
|
---|
49 | if check_store_xpdf_path(bin)
|
---|
50 | path = bin;
|
---|
51 | return
|
---|
52 | end
|
---|
53 | % Search the obvious places
|
---|
54 | if ispc
|
---|
55 | path = 'C:\Program Files\xpdf\pdftops.exe';
|
---|
56 | else
|
---|
57 | path = '/usr/local/bin/pdftops';
|
---|
58 | end
|
---|
59 | if check_store_xpdf_path(path)
|
---|
60 | return
|
---|
61 | end
|
---|
62 | % Ask the user to enter the path
|
---|
63 | while 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
|
---|
85 | end
|
---|
86 | error('pdftops executable not found.');
|
---|
87 |
|
---|
88 | function good = check_store_xpdf_path(path)
|
---|
89 | % Check the path is valid
|
---|
90 | good = check_xpdf_path(path);
|
---|
91 | if ~good
|
---|
92 | return
|
---|
93 | end
|
---|
94 | % Update the current default path to the path found
|
---|
95 | if ~user_string('pdftops', path)
|
---|
96 | warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.');
|
---|
97 | return
|
---|
98 | end
|
---|
99 | return
|
---|
100 |
|
---|
101 | function 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
|
---|
106 | good = ~isempty(strfind(message, 'PostScript'));
|
---|
107 | return |
---|