필터 지우기
필터 지우기

How can I open a PDF in a standalone application?

조회 수: 48 (최근 30일)
Bruj_gv
Bruj_gv 2024년 7월 31일 12:38
댓글: Walter Roberson 2024년 8월 13일 20:46
I want to create a standalone using App Designer in Mac. I manage for instance to create a simple app with a single push button that opens a pdf file:
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Button
function ButtonPushed(app, event)
system('open FILE_TEST.pdf');
end
It works perfectly fine but when I do the compilation (after ensuring FILE_TEST.pdf is included in the MATLAB Compiler's "Files required for your application to run") the program does not open the pdf.
Has anyone some idea on how the above code can be modified to open the pdf in the application? This only happens for Mac, doing the same to get a .exe file using winopen seems to work.
Many thanks.
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 8월 13일 20:46
My hypothesis is that FILE_TEST.pdf is not in the default directory that the standalone app runs under. See ctfroot

댓글을 달려면 로그인하십시오.

답변 (2개)

Steven Lord
Steven Lord 2024년 7월 31일 15:22
I would probably try calling the open function rather than using system.
You might need to explicitly add the openpdf function to the standalone application using the %#function pragma in the code you compile to create the application. [You can't call openpdf directly; it will be called by open when it sees you're trying to open a PDF file.]
  댓글 수: 1
Bruj_gv
Bruj_gv 2024년 8월 12일 12:38
Thank you very much for your proposed solution. Unfortunately, it is also not working for Mac.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2024년 7월 31일 14:56
I don't have a mac, nor a compiler anymore, but maybe try getting rid of open and letting the operating system figure it out just by the name of the file:
system('FILE_TEST.pdf');
Also, try putting the full path prepended to the base file name so it knows what folder to find it in. Like
folder = '\my stuff';
fullFileName = fullfile(folder, 'FILE_TEST.pdf');
commandString = sprintf('open "%s", fullFileName);
system(commandString);
I put double quotes around the filename because if the filename has any spaces in it, it will only pass the first "word" (up until the space) instead of the whole thing. The double quotes make it take the whole thing.
Does your compiled app bring up a console window? If not, don't use the -e option. See if there are any informative messages in the console window.
Lastly, see the FAQ:
If all that fails, call tech support.
  댓글 수: 2
Bruj_gv
Bruj_gv 2024년 8월 12일 12:39
Thank you very much for your proposed solution. Unfortunately, it is still not working. I have contacted tech support but the the standalone compiled application does not open the pdf file.
Image Analyst
Image Analyst 2024년 8월 13일 20:31
Is that what they said? That Macs just simply can't open PDF files from compiled MATLAB programs?
I no longer have a compiler so I can't test anything for you. Are you sure you tried with a super simple 4 line program like I gave you? Or did you try it from within your original, massive, main program?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Application Deployment에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by