Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Valid update to ps2pdf? Modified to work in deployed applications

1 回表示 (過去 30 日間)
Greg
Greg 2012 年 12 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I wanted to contribute an update to the 'ps2pdf.m' file provided in the File Exchange, but wasn't sure how. So I am posting this here in the hope that this info finds it's way into the right hands.
Many users have noted that the ps2pdf function does not work with the deployed applications. I figured out the changes needed to get it to work for me. I do not know if this will work for everybody, but this is what I did:
1) Copy the gscript.mexw32 (or analagous) file to your project, and include it on your path.
2) Modify the ps2pdf file as follows:
if ~isfield(gsData, 'cmd')
if isdeployed
mcr_root = getMcrRoot();
gsData.fontPath = fullfile(mcr_root, 'sys', 'gs8x','fonts','');
gsData.libPath = fullfile(mcr_root, 'sys', 'gs8x','ps_files','');
gsData.useBuiltin = 1;
gsData.cmd = @gscript;
else
v = ver('Matlab');
versionNumbers = regexp(v.Version,'(?<whole>\d+).(?<remain>\d+)','names');
versionWhole = str2double(versionNumbers.whole);
versionRemainder = str2double(versionNumbers.remainder);
if versionWhole < 7 || (versionWhole == 7 && versionRemainder < 4)
[gsCmd, ghostDir] = Local_GetOldGhostscript();
gsData.cmd = gsCmd;
else
% version 7.4 or later
[continue with existing code]
In addition, add a new local function that is called by the code above:
function mcr_root = getMcrRoot()
mcr_root = '';
possibleMcrPaths = cell(0);
if isunix
% TODO: REPLACE THESE PATHS WITH YOUR PATHS
possibleMcrPaths{1} = '/home/guy/randompath/matlab/matlab_r2007a/MCR/v76/';
possibleMcrPaths{2} = matlabroot;
else
possibleMcrPaths{1} = 'C:\Program Files(x86)\MATLAB\MATLAB Component Runtime\v79\';
possibleMcrPaths{2} = 'C:\Program Files\MATLAB\MATLAB Component Runtime\v79\';
possibleMcrPaths{3} = matlabroot;
% Check possible paths
for pathIndex = 1:length(possibleMcrPaths)
mcr_test = possibleMcrPaths{pathIndex};
if exist(mcr_test, 'dir')
mcr_root = mcr_test;
end
end
% Throw error if we did not find a valid directory
if isempty(mcr_root)
error('Could not find MCR');
end
end % function getMcrRoot
Note that I also fixed a bug with determining the Matlab version.
Thanks to Richard for providing this useful file!
I hope this helps!
  5 件のコメント
Muthu Annamalai
Muthu Annamalai 2012 年 12 月 6 日
Greg, alternatively you can post your version of the file on FileExchange, in what is called 'forking' the code. I believe BSD license required for all contributions to the FileExchange allows this; but don't quote me on this!
Fredrik Gustavsson
Fredrik Gustavsson 2018 年 7 月 5 日
I tried this with success and it saved me a lot of trouble. Thanks a lot for publishing this. This contribution should definitely be added to the ps2pdf FEX file, with the author's approval.

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by