2%PDFTOPS Calls a local
pdftops executable with the input command
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: http:
17% cmd - Command
string to be passed into
pdftops (e.g.
'-help').
20% status - 0 iff command ran without problem.
23% Copyright: Oliver Woodford, 2009-2010
25% Thanks to Jonas Dorn
for the fix
for the title of the uigetdir window on Mac OS.
26% Thanks to Christoph Hertel
for pointing out a bug in
check_xpdf_path under linux.
27% 23/01/2014 - Add full path to
pdftops.txt in warning.
28% 27/05/2015 - Fixed alert in
case of missing
pdftops; fixed code indentation
29% 02/05/2016 - Added possible error explanation suggested by Michael Pacer (issue #137)
30% 02/05/2016 - Search additional possible paths suggested by Jonas Stein (issue #147)
31% 03/05/2016 - Display the specific error message
if pdftops fails
for some reason (issue #148)
32% 22/09/2018 - Xpdf website changed to xpdfreader.com; improved popup logic
33% 03/02/2019 - Fixed one-off
'pdftops not found' error after
install (Mac/Linux) (issue #266)
34% 15/01/2020 - Fixed reported path of
pdftops.txt file in
case of error; added warning ID
35% 23/07/2020 - Fixed issue #311 (confusion regarding Xpdf-tools download/installation); silent check of
pdftops installation in
case no input arg specified
36% 21/02/2023 - Don
't display error dialog popup and fix messages in deployed apps
38 % If no command parameter specified, just check pdftops installation and bail out
40 xpdf_path(); % this will error if pdftops is not found
41 return % silent bail-out if pdftops was successfully located
45 [varargout{1:nargout}] = system([xpdf_command(xpdf_path()) cmd]);
48function path_ = xpdf_path
50 % Start with the currently set path
52 % Check the path works
53 if check_xpdf_path(path_)
56 % Check whether the binary is on the path
62 if check_store_xpdf_path(bin)
66 % Search the obvious places
72 for a = 1:numel(paths)
74 if check_store_xpdf_path(path_)
79 % Ask the user to enter the path
80 errMsg1 = 'Pdftops utility not found. Please locate the program, or
install xpdf-tools from
';
82 errMsg2 =
'"Xpdf command line tools" section';
83 fprintf(2,
'%s%s (%s)\n', errMsg1,
hyperlink(url1), errMsg2);
84 errMsg1 = [errMsg1 url1];
85 %
if strncmp(computer,
'MAC',3) % Is a Mac
86 % % Give separate warning as the MacOS uigetdir dialogue box doesn
't have a title
87 % uiwait(warndlg(errMsg1))
91 errMsg2 = ['(
' errMsg2 '. Ensure to
install xpdf-tools, not XpdfReader)
'];
92 errMsg = {errMsg1,errMsg2};
94 % Provide an alternative possible explanation as per issue #137
95 errMsg2 = 'If
pdftops is installed, maybe Matlab is shaddowing it, as described in
';
97 fprintf(2,
'%s%s\n', errMsg2,
hyperlink(url2,
'issue #137'));
98 errMsg2 = [errMsg2 url2];
100 % Provide an alternative possible explanation as per issue #311
101 errMsg3 =
'Or perhaps you installed XpdfReader but not xpdf-tools, as described in ';
102 url3 =
'https://github.com/altmany/export_fig/issues/311';
103 fprintf(2,
'%s%s\n', errMsg3,
hyperlink(url3,
'issue #311'));
104 errMsg3 = [errMsg3 url3];
106 errMsg = {errMsg1,
'',errMsg2,
'',errMsg3};
110 while ~isdeployed % only display the popup dialog
if not deployed
112 option1 =
'Install pdftops';
114 option1 =
'Issue #137';
116 answer = questdlg(errMsg,
'Pdftops error',option1,
'Locate pdftops',
'Ignore',
'Ignore');
117 drawnow; % prevent a Matlab hang: http:
119 case 'Install pdftops'
120 web(
'-browser',url1);
123 web(
'-browser',url2);
125 case 'Locate pdftops'
126 base = uigetdir(
'/', errMsg1);
128 % User hit cancel or closed window
131 base = [base filesep]; %#ok<AGROW>
132 bin_dir = {
'', [
'bin' filesep], [
'lib' filesep]};
133 for a = 1:numel(bin_dir)
134 path_ = [base bin_dir{a} bin];
135 if exist(path_,
'file') == 2
143 otherwise % User hit Ignore/Cancel or closed window
147 error(
'pdftops executable not found.');
151 % Check the path is valid
156 % Update the current
default path to the path found
157 if ~user_string(
'pdftops', path_)
158 %filename = fullfile(fileparts(
which(
'user_string.m')),
'.ignore',
'pdftops.txt');
159 [unused, filename] =
user_string(
'pdftops'); %#ok<ASGLU>
160 warning(
'export_fig:pdftops',
'Path to pdftops executable could not be saved. Enter it manually in %s.', filename);
166 % Check the path is valid
167 [good, message] = system([
xpdf_command(path_)
'-h']); %#ok<ASGLU>
168 % system returns good = 1 even when the command runs
169 % Look
for something distinct in the help text
170 good = ~isempty(strfind(message,
'PostScript')); %#ok<STREMP>
172 % Display the error message
if the
pdftops executable exists but fails
for some reason
173 % Note: on Mac/Linux, exist(
'pdftops',
'file') will always return 2 due to
pdftops.m => check for '/','.' (issue
#266)
174 if ~good && exist(path_,
'file') && ~isempty(regexp(path_,
'[/.]')) %#ok<RGXP1> % file exists but generates an error
175 fprintf(
'Error running %s:\n', path_);
176 fprintf(2,
'%s\n\n',message);
181 % Initialize any required system calls before calling
ghostscript
182 % TODO: in Unix/Mac,
find a way to determine whether to use
"export" (bash) or
"setenv" (csh/tcsh)
185 % Avoids an error on Linux with outdated MATLAB
lib files
186 % R20XXa/bin/glnxa64/libtiff.so.X
187 % R20XXa/sys/os/glnxa64/libstdc++.so.X
188 shell_cmd =
'export LD_LIBRARY_PATH=""; ';
191 shell_cmd =
'export DYLD_LIBRARY_PATH=""; ';
193 % Construct the command
string
194 cmd = sprintf(
'%s"%s" ', shell_cmd, path_);
function find(in vendor)
Return a list of scalar MATLAB strings containing the paths to all detected mpiexec binaries installe...
function ghostscript(in cmd)
function hyperlink(in url, in label, in msg)
function install(in vendor, in isyes)
Install or provide instructions to install the MPI library from the requested input MPI vendor.
function lib()
Return a scalar MATLAB string containing the path to the lib directory of the ParaMonte library packa...
function check_store_xpdf_path(in path_)
function check_xpdf_path(in path_)
function xpdf_command(in path_)
function user_string(in string_name, in string)
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...