1 function varargout = pdftops(cmd)
2 %PDFTOPS Calls a local pdftops executable with the input command
5 % [status result] = pdftops(cmd)
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.
11 % Once found, the executable is called with the input command
string.
13 % This
function requires that you have pdftops (from the Xpdf package)
14 % installed on your system. You can download
this from:
18 % cmd - Command
string to be passed into pdftops.
21 % status - 0 iff command ran without problem.
22 % result - Output from pdftops.
24 % Copyright: Oliver Woodford, 2009-2010
26 % Thanks to Jonas Dorn
for the fix
for the title of the uigetdir window on
28 % Thanks to Christoph Hertel
for pointing out a bug in check_xpdf_path
30 % 23/01/2014 - Add full path to pdftops.txt in warning.
33 [varargout{1:nargout}] = system(sprintf(
'"%s" %s', xpdf_path, cmd));
36 function path_ = xpdf_path
38 % Start with the currently
set path
39 path_ = user_string(
'pdftops');
40 % Check the path works
41 if check_xpdf_path(path_)
44 % Check whether the binary is on the path
50 if check_store_xpdf_path(bin)
54 % Search the obvious places
56 path_ = 'C:\Program Files\xpdf\pdftops.exe';
58 path_ = '/usr/local/bin/pdftops';
60 if check_store_xpdf_path(path_)
63 % Ask the user to enter the path
65 if strncmp(computer,'MAC',3) % Is a Mac
66 % Give separate warning as the uigetdir dialogue box doesn't have a
68 uiwait(warndlg('Pdftops not found. Please locate the program, or install xpdf-tools from http:
70 base = uigetdir('/', 'Pdftops not found. Please locate the program.');
72 % User hit cancel or closed window
75 base = [base filesep];
76 bin_dir = {
'', [
'bin' filesep], [
'lib' filesep]};
77 for a = 1:numel(bin_dir)
78 path_ = [base bin_dir{a} bin];
79 if exist(path_,
'file') == 2
83 if check_store_xpdf_path(path_)
87 error('pdftops executable not found.');
89 function good = check_store_xpdf_path(path_)
90 % Check the path is valid
91 good = check_xpdf_path(path_);
95 % Update the current default path to the path found
96 if ~user_string('pdftops', path_)
97 warning('Path to pdftops executable could not be saved. Enter it manually in %s.', fullfile(fileparts(which('user_string.m')), '.ignore', 'pdftops.txt'));
102 function good = check_xpdf_path(path_)
103 % Check the path is valid
104 [good, message] = system(sprintf('"%s" -h', path_));
105 % system returns good = 1 even when the command runs
106 % Look for something distinct in the help text
107 good = ~isempty(strfind(message, 'PostScript'));