MATLAB Answers

How to execute a print command for the MATLAB Web Broser from the command line

5 views (last 30 days)
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 Comments
Claus Andersson
Claus Andersson on 22 Jan 2021
Thanks for taking time answer my question. I really appreciate it.
The point is that the matlab browser window (try ">>web("https://www.amazon.com") is not 'printable' from the matlab command line, becuase the 'gcf' handle does not apply to the matlab web browser window. This windows really is different in a way; it has no matlab axes or matlab graphics. Any suggestions will help, and perhaps even utitlizing the java.lang library could fix it.I found out that >>com.mathworks.mlservices.MatlabDesktopServices.getDesktop.closeGroup('Web Browser')
will make the web window close, but I really dont know how to move on from here as regards a 'saveas' or 'save' command..

Sign in to comment.

Accepted Answer

Mario Malic
Mario Malic on 22 Jan 2021
Edited: Mario Malic on 22 Jan 2021
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);
There's also a possibility using websave combined with MATLAB Report Generator to convert html to other file formats.
  1 Comment
Claus Andersson
Claus Andersson on 22 Jan 2021
Thanks Mario. Thanks for helping out. I will try tomorrow how far it will take me.
Again - your time is highly appreciated!

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!