[7182] | 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 |
|
---|
[14174] | 35 | function path_ = xpdf_path
|
---|
[7182] | 36 | % Return a valid path
|
---|
| 37 | % Start with the currently set path
|
---|
[14174] | 38 | path_ = user_string('pdftops');
|
---|
[7182] | 39 | % Check the path works
|
---|
[14174] | 40 | if check_xpdf_path(path_)
|
---|
[7182] | 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)
|
---|
[14174] | 50 | path_ = bin;
|
---|
[7182] | 51 | return
|
---|
| 52 | end
|
---|
| 53 | % Search the obvious places
|
---|
| 54 | if ispc
|
---|
[14174] | 55 | path_ = 'C:\Program Files\xpdf\pdftops.exe';
|
---|
[7182] | 56 | else
|
---|
[14174] | 57 | path_ = '/usr/local/bin/pdftops';
|
---|
[7182] | 58 | end
|
---|
[14174] | 59 | if check_store_xpdf_path(path_)
|
---|
[7182] | 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)
|
---|
[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
|
---|
| 85 | end
|
---|
| 86 | error('pdftops executable not found.');
|
---|
| 87 |
|
---|
[14174] | 88 | function good = check_store_xpdf_path(path_)
|
---|
[7182] | 89 | % Check the path is valid
|
---|
[14174] | 90 | good = check_xpdf_path(path_);
|
---|
[7182] | 91 | if ~good
|
---|
| 92 | return
|
---|
| 93 | end
|
---|
| 94 | % Update the current default path to the path found
|
---|
[14174] | 95 | if ~user_string('pdftops', path_)
|
---|
[10635] | 96 | warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.');
|
---|
[7182] | 97 | return
|
---|
| 98 | end
|
---|
| 99 | return
|
---|
| 100 |
|
---|
[14174] | 101 | function 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
|
---|
| 106 | good = ~isempty(strfind(message, 'PostScript'));
|
---|
[10635] | 107 | return |
---|