How to execute a print command for the MATLAB Web Broser from the command line
조회 수: 11 (최근 30일)
이전 댓글 표시
As neither gcf, gcob, gca or the findall function can return a handle for the MATLAB web browser window, I cannot print from the command line. Can you help?
댓글 수: 4
Mario Malic
2021년 1월 21일
Are you trying to save the figure as an image?
exportgraphics(gcf, 'Image.png')
If not, please explain what kind of data are you trying to get.
I never used print, but try only calling the function in command window without input arguments, like this
print
you'll get your figure in new window in .pdf format.
채택된 답변
Mario Malic
2021년 1월 22일
편집: Mario Malic
2021년 1월 22일
Hello,
I found two ways of doing so, the first one is not great because it is not documented, and this may not be working in new releases (will not work once Java components are removed from MATLAB).
They both share the same con, and that is, once the code is ran, you have to manually finish the operation by entering filename and/or printer.
First option is through MATLAB's browser client:
desktop = com.mathworks.mde.desk.MLDesktop.getInstance;
web("https://www.google.com")
desktop.getClientTitles % In my case, Google was shown as a name for Browser Client
webBrowserClient = desktop.getClient('Google');
webBrowserPanel = webBrowserClient.getComponent(0); % Client has a Panel component
webBrowserWidgets = webBrowserPanel.getComponent(0) % Panel has Widgets and jPanel components
printButton = webBrowserWidgets.getComponent(5); % 5th component is print button
printButton.doClick; % This will make a programmatic click of the button and prompt you to choose printer and name
Second is through Internet Explorer:
ieHandle = actxserver('internetexplorer.application');
ieHandle.Visible = 1;
Navigate(ieHandle, 'https://www.google.com');
pause(1); % to load the webpage
ieHandle.ExecWB(6,2);
For arguments in ExecWB, see the method on https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752087(v=vs.85)
There's also a possibility using websave combined with MATLAB Report Generator to convert html to other file formats.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!